Hello all,
Mysql is reporting the wrong number of rows and I can't figure it out. I've looked over the code many times with no luck. I feel like the solution is easy, like the wrong syntax or something, but I am overlooking it. I need another pair of eyes to be sure.
I know that it is better to use COUNT() instead of mysql_num_rows, but count reports the wrong number of rows too so once this is fixed I can change it.
Here is the function:
function isBuilderOrphan($builder_id) {
connectToDatabase();
$orphan_sql = "SELECT builder_id
FROM new_construction
builder_id = $builder_id";
$result = mysql_query($orphan_sql) or die("Can't get builder id from orphan function!");
$numrows = mysql_num_rows($result);
// for debugging
echo $numrows . "<br>";
echo $orphan_sql . "<br>";
// if just that one entry
if ($numrows == 1) {
return true;
}
else { return false; }
}
The variable inside the function, reports the number of rows as 0. I took the SQL echoed out from the function and pasted it into the MySQL prompt and the query returned 1 row, which is correct.
So if the query doesn't die, and the SQL is correct, why is num_rows returning 0?
I tried changing variable names and freeing my mysql results, but nothing works. The funny thing is I have this exact code elsewhere and it works fine. This is such a simple function that I've done numerous times before, I just don't get it. Please help.
Thanks
-Samantha