Dynadot โ€” .com Transfer

While loop question

SpaceshipSpaceship
Watch

TwiztedFake

Established Member
Impact
1
I am working a listing of some information and I am stuck. How can I check if something is dividable by a number that equals a whole number.

Example.
while ($row = mysql_fetch_array($result))
{ echo ' $link' }

After five loops I want it to echo $info. Then return to the while loop until it gets to 10 then echo $info again, etc. Basically would echo $info every 6th loop.

Is there an easy way to do this with out having to code in a bunch of if statements.
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
The MOD operator, %

$i = 15 % 3;

This returns 0, since the remainder is 0.

$i = 15 % 4

This should return 3 since 15 / 4 leaves 3 as a remainder. If it's 0, it's divisable, basically.
 
1
•••
I hope this helps:

PHP:
$i = 0;

while ($row = mysql_fetch_array($result))
{
 if (($i++ % 5) == 0)
  echo $info;
 else
  //listing stuff
  echo ' $link';
}
 
0
•••
Thank you both, it works now. I knew there had to be an easier way than I was trying.
 
0
•••
why don't you use a varibale for counter whih increments everytime and if it is divisible by 5 with 0 as remainder then echo your $info.

That's it.

Thanks.
 
0
•••
Appraise.net
Escrow.com
Spaceship
Rexus Domain
CryptoExchange.com
Domain Recover
CatchDoms
DomDB
NameFit
  • The sidebar remains visible by scrolling at a speed relative to the pageโ€™s height.
Back