Is it possible to write multiple conditions in a while loop? If not, what is an alternative? I tried it and was returned with an error relating the line of code that sets up the conditions for the while loop. Here is an example of what I mean.
$s = 1;
while ($result_row = mysql_fetch_assoc($query) && $s < 5)
{
echo $result_row['id'];
$s++;
}
That is possible, but because
=has lower precedence than&&you need parentheses to ensure that your statement is interpreted correctly:The parentheses around
$s < 5are not required here, but I’ve included them for clarity.However it would be easier just to modify your query to only return 5 rows, by adding
LIMIT 5.