0

Hello Friends,

I am echoing out my articles from my DB (mysql) doing it 10 articles per page and i want to be echoing out advert in between the articles, that is echo our an advert after every two article. meaning on a page of 10 articles, i will have 5 adverts. pls how to i dothis.

Thanks,
adsegzy

2
Contributors
1
Reply
31
Views
3 Years
Discussion Span
Last Post by veedeoo
0

Here is a very simple example..

$article = array('1'=>'article one','2'=>'article two','3'=>'article three','4'=>'article four', '5'=>'article five', '6'=>'article six','7'=>'article seven','8'=>'article eight','9'=>'article nine', '10'=> 'article ten');
$this_ad = '<b>this is banner ad</b>';

$perpage = 10;
$ad_interval = 2;

$i= 0;
$out = '';

foreach($article as $item){

    $i++;
    $out .= $item.'<br/>';
    for($ad_x = $ad_interval; $ad_x <= $perpage; $ad_x += $ad_interval){

  if($i==$ad_x){
    $out .= $this_ad.'<br/>';
}

}

}

echo $out;

you can run the above codes here.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.