[thelist] something wrong with my SQL query
Rich Gray
rich at f1central.net
Wed Nov 20 16:33:01 CST 2002
At the risk of flogging a dead horse..
FWIW a variation on what rudy has suggested is that you can also use 'select
1 from menuitem where categoryid = $id' ... this will return the literal
number 1 if the row exists and a null value if it doesn't. There's no
significance in using the number 1 but it quite handily equates to true in
PHP...
e.g.
$result = mysql_query('select 1 from from menuitem where categoryid =
'.$id);
if ($result) {
$row = mysql_fetch_row($result);
if (is_null($row[0])) {
// Row doesn't exist
Blah Blah Blah
}
else {
// Row does exist
Yada Yada Yada
}
}
Cheers
Rich
-----Original Message-----
From: thelist-admin at lists.evolt.org
[mailto:thelist-admin at lists.evolt.org]On Behalf Of rudy
Sent: 20 November 2002 11:30
To: thelist at lists.evolt.org
Subject: Re: [thelist] something wrong with my SQL query
> > SELECT count(*) as numberofitems
> > FROM menuitem
> > WHERE categoryID = $id
> >
> > this will always return exactly one row, so then you just test the
> > count
>
> Actually, (I probably didn't make this clear) that would return as
> many as there are of that category. There could be 12 items of
> category 'lunch', (id=4 say) and so it would return 12..not one.
> Unless I have completely misunderstood...(which is entirely possible)
that query will always return exactly one row
that row will have one column, called numberofitems
that column will have a value of 0, or some other number
if it's 0, go ahead and delete the category
rudy
More information about the thelist
mailing list