Jump to content

while (query)


Eggzorcist

Recommended Posts

I'm having trouble with listing a query with while loops...

 

What am I doing wrong?

$user = $database->escape_value($_SESSION['username']);
while($row = mysql_fetch_assoc($database->query("SELECT * FROM project WHERE user = '{$user}'"))){
echo $row['name'];
}

 

 

THank you

Link to comment
https://forums.phpfreaks.com/topic/211196-while-query/
Share on other sites

You are re-executing the query in a forever-loop because you put the code that executes the query inside of the while() condition.

 

You would need to execute the query once, before the start of the while(){} loop, not inside of the while() condition. The while(){} loop should only iterate over the result set that the query returns.

Link to comment
https://forums.phpfreaks.com/topic/211196-while-query/#findComment-1101300
Share on other sites

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.