poopinthescoop Posted November 25, 2011 Share Posted November 25, 2011 $sql = "SELECT poster_id from phpbb_posts WHERE topic_id = ".$topic_id." "; $result = $db->sql_query($sql); //same as mysql_query $row = $db->sql_fetchrow($result); // same as mysql_fetch array. var_dump($row); With this code (i commented the query function for you) im getting array 'poster_id' => string '59' (length=2) When I run this into SQL in phpmyadmin I'm getting 59 56 //this is what I want I need to get all of the records, not just the first one. I have even tried using replacing the function with mysql_query and mysql_fetch_array any ideas? It's a bit late, so I may just be making a simple mistake. Thanks! Link to comment https://forums.phpfreaks.com/topic/251790-mysql-only-getting-the-first-record/ Share on other sites More sharing options...
Pikachu2000 Posted November 25, 2011 Share Posted November 25, 2011 Where's the while() loop you're using to fetch the records from the result resource? Link to comment https://forums.phpfreaks.com/topic/251790-mysql-only-getting-the-first-record/#findComment-1291139 Share on other sites More sharing options...
poopinthescoop Posted November 25, 2011 Author Share Posted November 25, 2011 Where's the while() loop you're using to fetch the records from the result resource? Shouldn't both values be inside of $row though? When I use a var_dump I'm only getting one value? I tried using a foreach, and every result came out with 59. Link to comment https://forums.phpfreaks.com/topic/251790-mysql-only-getting-the-first-record/#findComment-1291142 Share on other sites More sharing options...
Pikachu2000 Posted November 25, 2011 Share Posted November 25, 2011 No. You're selecting one field from each record. Each iteration of a loop over mysql_fetch_* will hold one record, with that record's selected field(s) in an array. Link to comment https://forums.phpfreaks.com/topic/251790-mysql-only-getting-the-first-record/#findComment-1291147 Share on other sites More sharing options...
poopinthescoop Posted November 25, 2011 Author Share Posted November 25, 2011 No. You're selecting one field from each record. Each iteration of a loop over mysql_fetch_* will hold one record, with that record's selected field(s) in an array. So I should loop this? $result = $db->sql_query($sql); Link to comment https://forums.phpfreaks.com/topic/251790-mysql-only-getting-the-first-record/#findComment-1291149 Share on other sites More sharing options...
poopinthescoop Posted November 25, 2011 Author Share Posted November 25, 2011 I got it, thanks! while($row = $db->sql_fetchrow($result)) { var_dump($row); }; Link to comment https://forums.phpfreaks.com/topic/251790-mysql-only-getting-the-first-record/#findComment-1291154 Share on other sites More sharing options...
Pikachu2000 Posted November 25, 2011 Share Posted November 25, 2011 In procedural style code, it would be like this. $sql = "SELECT poster_id from phpbb_posts WHERE topic_id = ".$topic_id." "; $result = mysql_query($sql); while( $row = mysql_fetch_row($result) ) { var_dump($row); } Link to comment https://forums.phpfreaks.com/topic/251790-mysql-only-getting-the-first-record/#findComment-1291157 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.