Code2004 Posted October 5, 2009 Share Posted October 5, 2009 Hi, earlier, I was writing some code for my new site, (in specific, making a guestbook + a class to work with it) and I found that the code below brings up only one result - when in fact, there are at least 10 in there already from me junking up the database for trials. <?php class Guestbook { ... public function getChatlog($limit) { global $database; $sql = "SELECT * FROM `chatlog` ORDER BY `chatlog_id` DESC LIMIT {$limit}"; $sql_res = $database->database_query($sql) or die($database->database_error()); $log = array(); while ($resource_info = $database->database_fetch_assoc($sql_res)) { $log = $resource_info; } return $log; } ... } ?> When I tested this function, like I said, it only returned one record for each field. The returned array was: Array ( [chatlog_id] => 3 [chatlog_name] => Visitor_77 [chatlog_message] => Lol [chatlog_time] => Monday 5th of October 2009 11:56:39 AM ) I have checked my SQL in phpMyAdmin and it's fine. To me, the loop looks fine too. I am stuck and lost... Need help! Thanks for any replies! Code2004 // Connor SonoRinato.com Many thanks. EDIT: just to note, the database wrapper is pretty simple and I've worked with it successfully before :S Link to comment https://forums.phpfreaks.com/topic/176602-solved-odd-mysql-error/ Share on other sites More sharing options...
cags Posted October 5, 2009 Share Posted October 5, 2009 I'm assuming that the value of $limit is greater than 1, so I imagine it's because you are overwriting $log not adding to an array. Try this instead... $log[] = $resource_info; Link to comment https://forums.phpfreaks.com/topic/176602-solved-odd-mysql-error/#findComment-931006 Share on other sites More sharing options...
Code2004 Posted October 5, 2009 Author Share Posted October 5, 2009 ... Yeah, I feel like an idiot now tyty xD So obvious, I've been staring at that for 10-15 mins! Thanks so much! :D Link to comment https://forums.phpfreaks.com/topic/176602-solved-odd-mysql-error/#findComment-931007 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.