Click to See Complete Forum and Search --> : sql query problem


mattastic
01-08-2006, 11:49 AM
Hi,

I'm trying to so a subquery but I keep getting this error:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\Program Files\xampp\htdocs\view-event.php on line 43

Here is my code, can anybody help?:

<?php
$query = "SELECT *
FROM tblequipment
WHERE equipmentID = (
SELECT equipmentID
FROM tblequipmentevent
WHERE eventid = '$eventid' )";
$result = mysql_query($query);

if ($myrow = mysql_fetch_array($result)) {
echo $myrow[equipmentID] . $myrow[description];

} else {
echo "No rooms are booked for this event yet!"; }

?>


Thankyou

NogDog
01-08-2006, 12:00 PM
For debugging during development:

$result = mysql_query($query) or die ($query . " -- " . mysql_error());

Mester Pediz
01-11-2006, 07:00 AM
Can't just tell what the error comes from, but if you after your query either use the "or die (mysql_error()) or just an "echo mysql_error()" it will print of where in the query the error occurs

mattastic
01-11-2006, 07:20 AM
Thanks for the replies.

It says I'm returning more than one result for the subquery.

Is there a better way I could do this?

Thankyou

chickenland
01-11-2006, 07:45 AM
I'm assuming this means that the sub query is returning more than one result, and the where = clause can only take one argument (i.e, WHERE foo=bar, not WHERE foo=bar,bar,bar,bar)

the only way to change this would be to LIMIT 1, but i'm not sure this is the result you are after ?

NogDog
01-11-2006, 11:09 AM
Or should it be ...WHERE equipmentID IN (SELECT... ?

chazzy
01-11-2006, 12:34 PM
or maybe you never defined the primary key as equipmentID in the table.