[thelist] something wrong with my SQL query

Mike Stenhouse Mike.Stenhouse at spiritsoft.com
Wed Nov 20 12:28:00 CST 2002


You could try doing:

"SELECT COUNT(item) AS itemcount FROM menuitem WHERE categoryID = $id"
and then testing for itemcount > 0 to print your error...

My two cents anyway...

Mike

-----Original Message-----
From: Tom Dell'Aringa [mailto:pixelmech at yahoo.com]
Sent: 20 November 2002 17:10
To: thelist at lists.evolt.org
Subject: [thelist] something wrong with my SQL query


Hi all, I am trying to disallow a deletion of a category if a
category exists already in a table. Here is my code:

//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);
}

I added a test category that is NOT in the menuitem table. Yet it
always tells me I can't delete it because it exists. I'm guessing
this has something to do with the way I set it up (if($result)??)

When I print out the $result I get "RESOURCE id" instead of the sql
so I'm wondering if my logic is wrong..

TIA

Tom

=====
var me = tom.pixelmech.webDeveloper();

http://www.pixelmech.com/
http://www.maccaws.com/
[Making A Commercial Case for Adopting Web Standards]

This message contains confidential information and is intended only for the named individual and may not be disseminated without prior permission.  If you are not the named addressee, you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately by e-mail if you have received this message in error and delete this e-message from your system. E-mail transmission cannot be guaranteed to be secure or error-free as information could be intercepted, corrupted, lost, destroyed, delayed in transmission, incomplete, or may contain viruses. The sender therefore does not accept liability for any errors or omissions in the contents of this Message which arise as a result of e-mail transmission.  If verification is required please request a hard-copy version. This message is provided for informational purposes and should not be construed as a solicitation or offer to buy or sell any software or services.

________________________________________________________________________
This email has been scanned for all viruses by the MessageLabs SkyScan
service. http://www.messagelabs.com
________________________________________________________________________



More information about the thelist mailing list