|
Posted by ZeldorBlat on 10/08/07 17:23
On Oct 7, 11:52 pm, BethH <hartman.b...@gmail.com> wrote:
> According to php.net, mssql_query is supposed to return true when no
> rows are returned. I'm actually getting an empty resource identifier
> instead of true.
>
> The table is empty, there are no rows in it at all, so mssql_query
> should always return true, but it isn't. Am I missing something?
> Here's my code:
>
> $StrQuery = "SELECT * FROM BookMarks WHERE UserName='" . $ID . "'";
> $Result = mssql_query($StrQuery);
>
> I'm not sure how I could have messed it up. I tried looking for bool-
> true (=== TRUE), but it didn't catch it. So then I tried any true (==
> TRUE), and it worked. So then I tried looking for a bool (is_bool)
> and it didn't catch it. Finally, I had it just print the result and
> it gives me a resource identifier.
>
> It keeps trucking through as if it had actually found something. But
> when I do this:
>
> while ($Row = mssql_fetch_assoc($Result)){
> [code to make a table with the data]
>
> };
>
> nothing happens, because, of course, there are no actual rows, only
> imaginary ones.
>
> I've changed my code to check if the array is false before starting
> the while loop, but that seems like a weird way to go just to see if
> there's any data to work with.
>
> Any Suggestions?
You're getting confused on the definition of "when no rows are
returned." They're talking about a query that doesn't actually return
rows, like insert, update, or delete. A query that returns a result
(like select) will always return a resource identifier, regardless of
how many rows are in the result.
Navigation:
[Reply to this message]
|