Jump to content

Mysql only getting the first record?


poopinthescoop

Recommended Posts

$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

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.

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);
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.