benedictbutlin
Technical User
what is the best way to limit the results of a while loop? i know i can do this as a 'for' loop, but reason i'm using a while loop is that i'm looping a mysql query like so...
what i'd like to do is limit the loop to 10 results, and the reason i'm not using LIMIT in my mysql query, is because i need to get both all the results, as well as reduce the results in my loop. if i were to use LIMIT in my mysql query then i'd need to query the database twice... and that would be take ages doing double the work
Code:
while ($row = mysql_fetch_array($query)) {
}
what i'd like to do is limit the loop to 10 results, and the reason i'm not using LIMIT in my mysql query, is because i need to get both all the results, as well as reduce the results in my loop. if i were to use LIMIT in my mysql query then i'd need to query the database twice... and that would be take ages doing double the work