[thelist] something wrong with my SQL query

Tony Light TonyLight at blueyonder.co.uk
Wed Nov 20 12:59:01 CST 2002


--
[ Picked text/plain from multipart/alternative ]
Tom Dell'Aringa asked why the following query always returns a result - so he never gets to delete a category...

> $result = @mysql_query("SELECT item FROM menuitem WHERE categoryID =
> $id");
> if($result)
> {
> $message = "Oops! You cannot delete that category, it is being used!
> If you really wish to delete this category, you must first remove it
> from any menu item that refers to it. - ";
>
> header("Location: manage_cat.php?message=".$message);
> }

I think it is because the SELECT query runs ok.  It might not actually return any rows!
$result would be false only if the query failed for some reason.
Try checking the value of mysql_num_rows($result).
If 0, you can delete your category, else show your error message.

Regards,
    Tony.


--




More information about the thelist mailing list