for loops and array

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mzfp2
Forum Contributor
Posts: 137
Joined: Mon Nov 11, 2002 9:44 am
Location: UK
Contact:

for loops and array

Post by mzfp2 »

Hi

I want to use a for loop to iterate through the contents of a mysql_reesult array

something like
for x = 10 to 20 d
{
print $mysql_result[x];
}

but i know this wouldnt work! what is the correct way?
pootergeist
Forum Contributor
Posts: 273
Joined: Thu Feb 27, 2003 7:22 am
Location: UK

Post by pootergeist »

really I think you should be looking toward using mysql to do the limiting itself, then just run a while to output all results within the limits set

$a = mysql_query("SELECT * FROM `table` WHERE secta='blat' LIMIT 10,10");
while($b = mysql_fetch_array($a))
{
// output here eg echo $b['secta'];
}

check LIMIT in the mysql manual - basically

1 figure - LIMIT 12 - means only shown 12 returns
2 figures - LIMIT 12,10 - means shown 10 returns starting from return number 12 - eg 12-21 (something like that anyway)
Post Reply