homepage Welcome to WebmasterWorld Guest from 54.226.0.225
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Inserting code between items in a loop
Show an ad after 2 loops
monkeythumpa




msg:3358414
 8:59 pm on Jun 4, 2007 (gmt 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);
}

 

eelixduppy




msg:3358421
 9:08 pm on Jun 4, 2007 (gmt 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

whoisgregg




msg:3359059
 1:20 pm on Jun 5, 2007 (gmt 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. :)

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved