[thelist] something wrong with my SQL query

Howard Cheng howcheng at ix.netcom.com
Wed Nov 20 12:09:01 CST 2002


The problem is that mysql_query returns a result resource IF THE QUERY IS
VALID.

Thus, even though there are no rows which match your query, you always get
a result identifier, because you query was valid.

Instead, you need to count how many rows you returned, like such:

$sql = "SELECT ...";
$result = @mysql_query($sql);

if (mysql_num_rows($result) > 0)
{
     $message = "...";
     header("Location:...");
}

At 09:10 AM 11/20/2002 -0800, Tom Dell'Aringa wrote:
>//first check and see if the category is being used. If it is,
>disallow deletion
>
>$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);
>}

::::::::::::::::::::::::::::::::::
Howard Cheng
http://www.howcheng.com/ <-- NEW!
howcheng at ix dot netcom dot com
AIM: bennyphoebe
ICQ: 47319315




More information about the thelist mailing list