That means you only have one username in your database. That is why you are only getting a single user. If you had more than one user, var_dump would display an array with all of your usernames.
Check your MySQL query to make sure it is correct. Or add users to your database.
I've got 5 users in the database.
I'll be looking at the code to see if I find anything, if you figure out anything, please reply and let me know.
Thanks man.
You may have 5 users in your database. It might be that your query limits the value using either the LIMIT keyword or a WHERE clause to narrow the list down. Need more code
Does the online() function only print one user or all five? If all, then the query is working fine and you can just collect the usernames in an array. If only one, something is broken in the db or the query itself (though it looks okay).
The query is straightforward, so it's something else. Toss in a test line to see how many it thinks it's getting back. Use mysql_num_rows(). Try something like this:
PHP Code:
// in function online() $users = $queries->userQuery(); // add here die('rows returned: '.mysql_num_rows($users)); // while($user = mysql_fetch_array($users)) {
Or change it to an echo/print. Just get the number. Since you're only getting one result printed, it should show 1. If so, check your data again. Then do some debugging around the query. Echo/print it, dump the vars inside, etc.
It shows I'm getting 5, as said.
See, when I echo it inside the loop, I'm getting all of it.
That's not what you said before:
Quote:
Only one comes out of it.
You need to decide which is really happening. I'll assume that you didn't know what you were talking about last time and that you really mean the online() function does in fact print all five entries - as you've just said.
In that case, the method already suggested should work for you, though it might need a slight modification).
PHP Code:
// in function online() $users = $queries->userQuery(); // add here $usernames = array(); // while($user = mysql_fetch_array($users)) { // add here $usernames[] = $user['username']; // /* .. other stuff .. */ } // add here var_dump($usernames); //