Jump to content

While loop, returned by 10 each time.


ChrisMartino

Recommended Posts

Hello there, well basically my dilemma is that I need to make my while loop only list in orders of 10's so for example if I brought the value '500' from the database I want to list it in order of 10's e.g:

 

while($Value = mysql_fetch_array($TheQuery))
{
        echo("this would be a integer retruned in a 10");
}

 

So basically I want the figure '500' to be divided up and make it list in the while loop in 10's, does anyone have any suggestions on the best way to accomplish this?.

Link to comment
https://forums.phpfreaks.com/topic/208057-while-loop-returned-by-10-each-time/
Share on other sites

I'm pretty sure you can do that with incrementation.

 

For example:

 

$ii = 0;
$i = 10;
while($i <= 500) {
$query = mysql_query("SELECT * FROM table LIMIT $ii, $i;");
while($row = mysql_fetch_array($query)) {
// whatever whatever whatever
}
$ii = $i;
$i = $i + 10;
}

 

The code probably doesn't work, but you should get what I'm saying. I'm just using my logic here, and it should work.

 

Good luck mate,

Andy.

Thanks guys, after some massive brainstorming for a few hours I managed to get this working to my requirements, thanks to everybody that helped me with this!:

 

for ($i = 10; $i < $Package['package_max_slots']; $i += 10) 
{ 
echo $i;
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.