How can i do this?

Discussion in 'PHP' started by srobona, Jan 27, 2008.

  1. #1
    Hello friends,

    I need a solution for this:

    Suppose i have got 20 links from a query to display them in a column like

    link 1
    link2
    link3
    .....
    .....
    link20

    No problem up to this portion. But now i want to show a google ad after every 5th link like

    link1
    .....
    link5
    google ad here

    link6
    .....
    link10
    google ad here

    link11
    .....
    link15
    google ad here

    link16
    .....
    link20
    google ad here

    Any idea or solution? Thanks in advance :)
     
    srobona, Jan 27, 2008 IP
  2. Alam

    Alam Active Member

    Messages:
    316
    Likes Received:
    91
    Best Answers:
    0
    Trophy Points:
    68
    #2
    You can Try-

    <?
    $sl=1;
    for($a=1;$a<=23; $a++)
    {
    echo $a."<br>";
    if(($sl/5)!=(is_float($sl/5)))
    {
    echo "Your Google Ad Here<br>";
    }
    $sl=$sl+1;
    }
    ?>

    if fulfill your requirement, plz apply green repu ;)
     
    Alam, Jan 27, 2008 IP
  3. kreoton

    kreoton Peon

    Messages:
    229
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #3
    <?php
    $counter = 0;
    foreach ($yourlinks as $link)
    {
    	echo $link.'<br />';
    	$counter++;
    	if ($counter%5 == 0)
    		echo $google_ad_code;
    }
    ?>
    
    PHP:
     
    kreoton, Jan 27, 2008 IP
    srobona likes this.
  4. srobona

    srobona Active Member

    Messages:
    577
    Likes Received:
    57
    Best Answers:
    0
    Trophy Points:
    88
    #4
    Thanks a lot for the solution :) rep added
     
    srobona, Jan 30, 2008 IP