While() will skip one SQL entry?

Ask about a PHP problem here.
Post Reply
User avatar
Helx
Posts: 350
Joined: Thu May 17, 2012 6:45 am
Location: Auckland, New Zealand

While() will skip one SQL entry?

Post 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:
[syntax=php]<?php while($user = mysql_fetch_array($usr_list)){ ?>
<td><?php echo $user['username']; ?></td>
<td><?php echo $user['id']; ?></td>
<?php } ?>[/syntax]

Will only show 2 of the 3 DB entries.

My SQL query:
[syntax=php]$usr_list = mysql_query("SELECT * FROM acc WHERE `group_id` = '{$gid}' AND `deleted` = 0 AND `admin_of_group` = '{$session_NAME}'");[/syntax]

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 :/
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: While() will skip one SQL entry?

Post by jacek »

I only see two rows that have deleted = 0 :?
Image
User avatar
Helx
Posts: 350
Joined: Thu May 17, 2012 6:45 am
Location: Auckland, New Zealand

Re: While() will skip one SQL entry?

Post 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
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: While() will skip one SQL entry?

Post 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
Image
User avatar
Helx
Posts: 350
Joined: Thu May 17, 2012 6:45 am
Location: Auckland, New Zealand

Re: While() will skip one SQL entry?

Post 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 :) )
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: While() will skip one SQL entry?

Post by jacek »

Then I have no idea what the problem is :P Can you explain it again ?
Image
Post Reply