So, I have a database (With a table called users) that let’s users connect accounts, and it goes by their usernumber to find their accounts, let’s say (With values):
Usernumber|Username|Email
-------------------------
1 | Justin | email@email.com
2 | Test | test@test.com
2 | Hi | gah@goo.com
1 | Foo | hey@hey.com
1 | Bar | Du@de.com
Now, in PHP, I do:
$stuff = mysql_fetch_array(mysql_query("SELECT * FROM users WHERE usernumber=1"));
Now, I do count($stuff); and it returns 14, all the time, whether I do it with usernumber one or two… I can’t figure out the problem, but I was wondering if someone else sees it, or knows something that I don’t about how certain files are configured (Limits or something?). I’m using XAMPP to test everything right now.
ALSO, when I do the $stuff in PHPMYADMIN as a SQL in the table, it does return all the values it should.
So question is: What am I missing and how do I get it return all the values and not just 2 rows? (The table has 7 columns).
Thanks,
Justin W.
By default,
mysql_fetch_arraywill return a combined indexed array of columns (0 – 6) and associative array (column_name => value)That is why you have 14 values for that row (7 that are numerically indexed, 7 that are associatively indexed).
Also, you only get one row per function call. 14 is the number of columns (7 * 2), not the number of rows.
You need to start holding your MySQL result resource in its own variable:
That way you can call
mysql_fetch_arraymultiple times on that resultset. Also, you can check the number of rows by callingmysql_num_rows($result)