Page 1 of 1

While() will skip one SQL entry?

Posted: Sun Sep 23, 2012 10:55 am
by Helx
Another issue I'm having with MySQL;

Lets say I have 3 user profiles in a MySQL DB:

|username|ID|group_id|deleted|admin_of_group|
------------------------------------------------------------
|test1......| 1|........2|.......0|............person|
|bob........| 2|........1|.......0|..........abcedea|
|gary.......| 3|........2|.......1|............person|
------------------------------------------------------------

The following code:
<?php while($user = mysql_fetch_array($usr_list)){ ?>
<td><?php echo $user['username']; ?></td>
<td><?php echo $user['id']; ?></td>
<?php } ?>
Will only show 2 of the 3 DB entries.

My SQL query:
$usr_list = mysql_query("SELECT * FROM acc WHERE `group_id` = '{$gid}' AND `deleted` = 0 AND `admin_of_group` = '{$session_NAME}'");
I'm pretty sure that its not the query, because I tried it directly in phpMyAdmin with no issues.

However if I order the results by username, then it would show the result previously hidden, and hide one of the results previously shown.

I have tried using a var_dump() in the while loop, and it only returned:
bool (false)
And because a while loop only runs when the input is true...

I simply don't know whats making it false :/

Re: While() will skip one SQL entry?

Posted: Fri Sep 28, 2012 12:57 pm
by jacek
I only see two rows that have deleted = 0 :?

Re: While() will skip one SQL entry?

Posted: Fri Sep 28, 2012 10:00 pm
by Helx
*will only show 1

I only put the deleted row in after posting, so there was a bit of understanding to my table :3

Re: While() will skip one SQL entry?

Posted: Wed Oct 03, 2012 3:12 pm
by jacek
I meant, if you look at the data in the table there is only one row that is not marked as deleted for each group_id. So you should be getting only one row as the result from that SQL :s

Re: While() will skip one SQL entry?

Posted: Wed Oct 03, 2012 3:17 pm
by Helx
Probably boils down to how I made the post;

The user is considered as deleted if the deleted row is 0, so the only person I was meant to delete is 'Gary' (made-up name by the way :) )

Re: While() will skip one SQL entry?

Posted: Wed Oct 03, 2012 5:23 pm
by jacek
Then I have no idea what the problem is :P Can you explain it again ?