MySQL Query returning double requested rows, which are empty. [PHP]

Status
Not open for further replies.
Hi there,

Usually I'm able to solve problems by looking them up on Google and what not, but I cannot, for the life of me, figure out what is going on.

I have a table in my database (pre_users), which contains six columns (id, email, password_hash, group_id, registration_timestamp, and banned). All I want is the first four columns of this table. So, like usual, I do the following:

Code:
$sql1 = "SELECT id, email, password_hash, group_id FROM pre_users WHERE id=1";
$res1 = mysql_query($sql1);
$array1 = mysql_fetch_array($res1);

Now, I have never had this not work, and never had it do this. Instead of retrieving just the four items of data I need and putting them into the array (1, 741ca4f041c938a296d8f8f90bcad351, , 1), it returns the following: , , , , , 1, 741ca4f041c938a296d8f8f90bcad351, [email], 1. That is double the requested result (4 requested, 8 returned), and the double set being empty.

I've attempted to ignore this by using a combination of array_unique(), array_push() (as a second array, similar to this, needs to be tacked onto the end of this one. Also of note, this same occurrence happens with that array was well.), etc., but cannot get it to work. Any ideas or help will be VERY much appreciated. I'm about to throw my computer out the window.
 
Code:
$array1 = mysql_fetch_array($res1);

you're not specifying any result type for the mysql_fetch_array function - it defaults to MYSQL_BOTH, which returns an array that's contains both associative and number indices, aka double the requested data set. as to why it's showing up blank for the first half of the result set, that beats me :confused:

try using
Code:
mysql_fetch_array($res1, MYSQL_NUM);
and then accessing the results by parsing
Code:
$res1[i]
where i is 0 thru one less than the requested number of results.
 
Status
Not open for further replies.