daveoffy Posted February 28, 2009 Share Posted February 28, 2009 I need it to echo all my database entries, right now it only echos the last one. $username = $_COOKIE['username']; $qry = "SELECT * FROM users WHERE username = '$username'"; $qresult = mysql_query ($qry); while($row = mysql_fetch_array($qresult)) $id = $row['id']; $sql = "SELECT * FROM site WHERE id = '$id'"; $sresult = mysql_query ($sql); while($site = mysql_fetch_array($sresult)) $site_name = $site['site']; echo $site_name.'<br>'; unset($id); unset($site_name); Link to comment https://forums.phpfreaks.com/topic/147330-solved-only-echos-last-database-entry/ Share on other sites More sharing options...
corbin Posted February 28, 2009 Share Posted February 28, 2009 Change while($site = mysql_fetch_array($sresult)) $site_name = $site['site']; echo $site_name.'<br>'; To while($site = mysql_fetch_array($sresult)) { $site_name = $site['site']; echo $site_name.'<br>'; } while(condition) expression Is the syntax of a while loop. If you want more than 1 expression to be executed, you must use {}. Link to comment https://forums.phpfreaks.com/topic/147330-solved-only-echos-last-database-entry/#findComment-773337 Share on other sites More sharing options...
daveoffy Posted February 28, 2009 Author Share Posted February 28, 2009 Thanks, I can't believe I forgot about that. It has been a while since I have typed PHP. Link to comment https://forums.phpfreaks.com/topic/147330-solved-only-echos-last-database-entry/#findComment-773346 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.