tags:

views:

208

answers:

4

The following errors,so must be wrong,but what is the correct way to do this:

$query = "SELECT * FROM tblProducts WHERE ProductId ='$SCId' AND SELECT * FROM tblProducts WHERE Cat ='$CatType' AND Type ='$TypeType'";

$rsPrimary = mysql_query($query) or die ("Query '$query' failed with error message: \"" . mysql_error () . '"'); $num=mysql_numrows($rsPrimary); mysql_close();

+1  A: 

The 'AND' statement in your WHERE clause is expecting a condition on its right hand side. You cannot place a SELECT query there.

+7  A: 
    SELECT * FROM tblProducts WHERE ProductId ='$SCId' 
                                  OR (Cat ='$CatType' AND Type ='$TypeType')
Peter
+2  A: 

Looks to me like what you really want is:

select * from tblProducts
where ProductId ='$SCId'
or ( Cat ='$CatType' AND Type ='$TypeType' )
Stephen ODonnell
A: 

The answers already given are correct for your query, however if, in the future you want to append the results of two or more select statements together you should take a look at UNION or UNION ALL. So your original query would have worked if you replaced your first and with UNION.
UNION removes duplicates from the results, UNION ALL doesn't and is therefore faster.

pipTheGeek