Jump to content


Photo

Displaying Results, something, Then more results, etc.


  • Please log in to reply
2 replies to this topic

#1 last_trace

last_trace
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 08 August 2006 - 07:48 PM

I am wondering how to do this with my ads. Look below..


Website Link
Website Link
Website Link

ADVERTISEMENT

Website Link
Website Link
Website Link


I want to be able to display 3 results, then show 1 ad, then show 3 more. So for every 3 results, it returns a ad, then 3 more if there are more.

I wasn't sure if I could do this with foreach some how or not.

#2 Orio

Orio
  • Staff Alumni
  • Advanced Member
  • 2,491 posts

Posted 08 August 2006 - 07:53 PM

Use the % (modular) operator :)

<?php
$link="www.domain.com";
$i=1;
while($i<100){ //let's say we want to print 100 times
if($i%4==0){
echo("ad");
}
else{
echo $link;
}
}
?>

Basicly, we check in each round if $i can be devided by 4, and if so print ad :)

Orio.
Think you're smarty?

(Gone until 20 to November)

#3 last_trace

last_trace
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 08 August 2006 - 07:54 PM

Wow, that was wicked fast and it worked.

Thank you so much.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users