dean7 Posted August 14, 2010 Share Posted August 14, 2010 hi all, I have a piece of code which I coded where it selects all there cars out of the database and shows them, well it is meant to: $getall = mysql_query("SELECT car, id FROM garage WHERE owner='$username'"); $gotall = mysql_fetch_object($getall); echo "$gotall->car - $gotall->id<br />"; Its meant to echo out all the cars which the user own, but for some reason its only echoing one car. Can anyone see why its only showing one car with the id not all the cars they own? Thanks. Link to comment https://forums.phpfreaks.com/topic/210740-echoing-everything-from-the-database/ Share on other sites More sharing options...
Skewled Posted August 14, 2010 Share Posted August 14, 2010 You have to use a loop.. <?php $getall = mysql_query("SELECT car, id FROM garage WHERE owner='$username'"); while($row = mysql_fetch_array($getall)){ echo $row['car']. " - ". $row['id']; echo "<br />"; } ?> Link to comment https://forums.phpfreaks.com/topic/210740-echoing-everything-from-the-database/#findComment-1099320 Share on other sites More sharing options...
dean7 Posted August 14, 2010 Author Share Posted August 14, 2010 You have to use a loop.. <?php $getall = mysql_query("SELECT car, id FROM garage WHERE owner='$username'"); while($row = mysql_fetch_array($getall)){ echo $row['car']. " - ". $row['id']; echo "<br />"; } ?> Thanks, that worked Link to comment https://forums.phpfreaks.com/topic/210740-echoing-everything-from-the-database/#findComment-1099321 Share on other sites More sharing options...
Skewled Posted August 14, 2010 Share Posted August 14, 2010 Your most welcome. Link to comment https://forums.phpfreaks.com/topic/210740-echoing-everything-from-the-database/#findComment-1099323 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.