At 10:48 PM -0400 8/2/99, Silicon Ghost wrote:
>I'm using PHP3 and mySQL.
>
>Here's my problem:
>
>I first run a query such as:
>$result = mysql_query("SELECT * FROM sites WHERE ID=1",$db);
>
>Now I want to do a check to see if the query found anything by doing something
>like:
>
>if $result==""
> echo("No result")
>else
> echo("Result is: $result");
>
>The problem I'm having is when there IS no result (and I know there isn't), it
>doesn't store the value of NULL or "" in $result. It still thinks $result has
>a value, sometimes showing what the last valid result was (most likely because
>it was left over in memory I would assume).
>
>I've toyed around with mysql_store_result and mysql_use_result, but without
>any luck. I'm a beginner at this so I may be using the wrong syntax.
>
>Any suggestions?
mysql_query() returns true if the query succeeds, and false if it
fails. Failure means the that there was an error, and success means
that the query could be executed successfully. This implies nothing
about the number of rows that the query returns. A query can be
successful but return no rows ("SELECT * FROM tbl_name WHERE 1 = 0",
for example).
Try passing your $result variable to mysql_num_rows() if mysql_query()
returns success.
--
Paul DuBois, paul@stripped