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

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.