Jump to content

Recommended Posts

Hi,

 

I've been breaking my head all evening trying to figure this out. I'm not new to php or mysql and I've used mysql_fetch_array dozens of times, but now it's got me puzzled.

I've got following code:

$sql = "select user_id from sales_users where sales_id = ".$user['id'];

$res = mysql_query($sql);

 

echo mysql_num_rows($res);

 

$clients = mysql_fetch_array($res);

 

It's a database containing users(sales_id) tied to clients(users_id). Each is is salesman for one or more clients, so obviously the resulting array has one or more rows. Whensales_id is 44, there are 3 rows: user_id's 4,13 and 45.

The echo of mysql_num_rows tells me there are indeed 3 rows. Now here it comes: when I convert the results to an array, I only get 1 element in the array, user_id 4. When I change the user_id's, it always returns the lowest user_id and leaves the other 2 behind. A print of the resulting array:

Array

(

    [0] => 4

)

What am I overlooking? Up until now this has always worked well for me, but now I really don't see what could be wrong. Maybe I've just been busy for too long today...

Link to comment
https://forums.phpfreaks.com/topic/55313-problem-with-mysql_fetch_array/
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.