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.


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){

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

    $out .= $this_ad.'<br/>';



echo $out;

you can run the above codes here.