Jump to content

SELECT query only returns one row


K_N

Recommended Posts

I have a very small table right now, looks just like this:

l4M3J.png

 

 

I'm using the following code

	
$watchQuery = "SELECT `watched` FROM `watch` WHERE `watcher` = '1'";
$watching = mysql_fetch_array(mysql_query($watchQuery));

 

And the array $watching comes out like this:

[0] => 0 [watched] => 0

 

What obvious mistake am I looking over that is causing this query to not select every row with a 'watcher' value of 1 (i.e. All of them)?

Link to comment
https://forums.phpfreaks.com/topic/233569-select-query-only-returns-one-row/
Share on other sites

It's certainly selecting all the rows that match, but if you don't loop through the results, you'll only see one result.

 

while( $array = mysql_fetch_assoc($watchQuery) ) {
     echo "Watched: {$array['watched']}<br>";
}

It's certainly selecting all the rows that match, but if you don't loop through the results, you'll only see one result.

 

while( $array = mysql_fetch_assoc($watchQuery) ) {
     echo "Watched: {$array['watched']}<br>";
}

D'oh. I'm doing the same thing 3 other times in this script. Can't believe I missed that.

 

 

Well, on my other issue, can you inform me on how to strip the index out of the array, so it only shows up as

[watched] => 0 [watched] => 1 [watched] => 2

etc? Or should I take that to the PHP forum?

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.