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

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.