July 26th, 2013, 12:18 AM
Getting 0 rows from query, but phpMyAdmin returns plenty!
Here's the strange part -- if I paste the SQL code into phpMyAdmin, I get 2 rows, no problem.
$query = "SELECT * FROM employees WHERE 1";
// Handle keeps coming back NON-NULL
$handle = mysql_query($query);
// These both report nothing.
$errno = mysql_errno();
$error = mysql_error();
// Reports 0.
$nNumRows = @mysql_numrows($handle);
// $row keeps coming back NULL.
$row = mysql_fetch_array($handle, MYSQL_ASSOC);
How can this be explained?
NOTE: My database query isn't literally that simple. It has 1 join statement. But that shouldn't matter, since phpMyAdmin likes my query just fine, right?
It can't be a problem with my SQL code, because when I paste it into a text file, remove the PHP code (variables, quotes, semicolons, etc.) and paste it into phpMyAdmin, it runs and returns 2 rows. I don't change any of the SQL code; I just fill in the variables with a sample keyword.
July 26th, 2013, 08:42 AM
Why in the name of anything(!) did you suppress the error on the get num rows line? THERE'S YOUR PROBLEM.
Never use the @ symbol. Just plain stupid. If there's an error in your code, YOU should know about it and here you are in the development stage and hiding errors and wondering why you aren't getting results.
I do mean it - your problem lies in the suppressed line. Try it and you'll see. (That is - IF you have error checking turned on.) Or you could use your time to look up that function name in the manual. Hmmm.....
July 26th, 2013, 11:41 PM
1) You specifically and deliberately suppress the errors from one of your functions, as someone has already said.
2) You post your code on a forum asking for help, then say "note, this isn't actually my code, but that shouldn't matter." A mechanic can't fix my car by looking at my brother's car.
3) As stated above, removing the @ will show you a real error (assuming you actually show yourself your code's errors) and it will be apparent what the problem is.
HEY! YOU! Read the New User Guide and Forum Rules
"They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin
"The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002
Think we're being rude? Maybe you asked a bad question
or you're a Help Vampire.
Trying to argue intelligently? Please read this.