cyrix Posted June 12, 2007 Share Posted June 12, 2007 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... Quote Link to comment https://forums.phpfreaks.com/topic/55313-problem-with-mysql_fetch_array/ Share on other sites More sharing options...
Wildbug Posted June 12, 2007 Share Posted June 12, 2007 It only fetches one row at a time. It's fetching the first row, which has one value: 4. You'll need to poll it as many times as you have values, or while-loop it and fill an array ($array[] = $row[0]) to get all the values. Quote Link to comment https://forums.phpfreaks.com/topic/55313-problem-with-mysql_fetch_array/#findComment-273413 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.