Welcome to WebmasterWorld Guest from 54.156.92.243

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Inserting code between items in a loop

Show an ad after 2 loops

     
8:59 pm on Jun 4, 2007 (gmt 0)

Preferred Member

10+ Year Member

joined:Aug 2, 2004
posts:551
votes: 0


I need to show an evil advertisement after every two loops in order to get rich. I have my "while" loop, simplified for illustration. How to I put a javascript call after each 2 rows?


while($result = mysql_fetch_array( $data ))
{
echo "a bunch of HTML";
echo "<div class=\"descr\">Posted on " . date('D j M Y',$result['posted']);
echo CutText(strip_tags($result['descr'], '<example>'),100);
}
9:08 pm on June 4, 2007 (gmt 0)

Senior Member

joined:Nov 12, 2005
posts:5967
votes: 0


Here's where a little math comes in :)

$counter = 0;
while($result = mysql_fetch_array( $data ))
{
if(($counter % 3) == 0) { #uses the modulus operator (%)
#print javascript
}
$counter++;
echo "a bunch of HTML";
echo "<div class=\"descr\">Posted on " . date('D j M Y',$result['posted']);
echo CutText(strip_tags($result['descr'], '<example>'),100);
}

good luck

1:20 pm on June 5, 2007 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member whoisgregg is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Dec 9, 2003
posts:3416
votes: 0


I need to show an evil advertisement after every two loops in order to get rich.

I lol'ed. Thanks for starting my day right monkeythumpa. :)

 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members