Reputation: 41
I have some PHP code,
$gQ = $mysqli->query("SELECT * FROM `Inventory` WHERE `UserID`='$user[ID]' ORDER BY `ID`");
$gN = $gQ->num_rows;
echo($gN);
My $user[ID] is 1, so it should fetch anything in Inventory that is owned by UserID 1. When I run the query:
SELECT * FROM `Inventory` WHERE `UserID`='1' ORDER BY `ID`
In PhpMyAdmin, it returns 1 row (because there is only 1 row!)
Whereas on the page it returns the number 2.
Why is this? I want it to echo 1 rather than 2.
Upvotes: 0
Views: 67
Reputation: 1204
Make sure your table userID is set to auto_increment, this will assure no duplicate userids (which you obviously have if SQL is bringing 2) use PHP MyAdmin if you can to look at all table records. If the rows are coming out the same double check how you are echoing out your data (would be duplicate code)
Upvotes: 0
Reputation: 157870
MySQLi finds two rows when there's only one?
No.
Mysqli finds exactly the number of rows found. Whatever inconsistencies and mistakes are caused by your code and/or various typos.
Upvotes: 3