zelig Posted April 4, 2012 Share Posted April 4, 2012 For some reason, I can only get 1 row to echo out when there are actually multiple rows in the database that should be echoing. Here is what I have: $result = mysql_query("SELECT * FROM boards WHERE boardname='$board' ORDER BY id LIMIT 10"); $post = mysql_fetch_assoc($result); echo stripslashes($post['message']) . "<br>\n" . " --- ".stripslashes($post['username']). " on ".stripslashes($post['time']) ."\n<hr width=90%>\n"; It pulls the one record great, but it only shows one record... I want to keep it to 10 records, thus the LIMIT in there (which I think I did right...), but it won't even show the ones in there right now (under 10, so that's not an issue yet). Link to comment https://forums.phpfreaks.com/topic/260351-more-than-1-row-to-echo-out/ Share on other sites More sharing options...
Psycho Posted April 4, 2012 Share Posted April 4, 2012 mysql_fetch_assoc() only pulls one record at a time from the result set. You will need a loop to get all the records. The manual for mysql_fetch_assoc() has an example script on how to do this. http://php.net/manual/en/function.mysql-fetch-assoc.php Link to comment https://forums.phpfreaks.com/topic/260351-more-than-1-row-to-echo-out/#findComment-1334409 Share on other sites More sharing options...
zelig Posted April 4, 2012 Author Share Posted April 4, 2012 Hmm... I tried doing a loop, but I have to confess, I'm not overly familiar with them. I got an error: Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource Here is the code I have now: result = mysql_query("SELECT * FROM boards WHERE boardname='$board' ORDER BY id LIMIT 10"); $post = mysql_fetch_assoc($result); while ($row = mysql_fetch_assoc($post)){ echo stripslashes($row['message']) . "<br>\n" . " --- ".stripslashes($row['username']). " on ".stripslashes($row['time']) ."\n<hr width=90%>\n";} What did I do wrong, so I can learn from it? Link to comment https://forums.phpfreaks.com/topic/260351-more-than-1-row-to-echo-out/#findComment-1334417 Share on other sites More sharing options...
litebearer Posted April 4, 2012 Share Posted April 4, 2012 try $query = "SELECT * FROM boards WHERE boardname = '$board' ORDER BY id LIMIT 10"; $result = mysql_query($query); while ($row = mysql_fetch_array($result)){ echo stripslashes($row['message']) . "<br>" . " --- ".stripslashes($row['username']). " on ".stripslashes($row['time']) ."<hr width=90%>"; } Link to comment https://forums.phpfreaks.com/topic/260351-more-than-1-row-to-echo-out/#findComment-1334419 Share on other sites More sharing options...
zelig Posted April 4, 2012 Author Share Posted April 4, 2012 Worked. Thanks litebearer! Link to comment https://forums.phpfreaks.com/topic/260351-more-than-1-row-to-echo-out/#findComment-1334420 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.