Link to home
Start Free TrialLog in
Avatar of Pete Winter
Pete WinterFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Where id = xxx or xxx or xxx

How do I write the following...

See code below:

$query_rs_spares_also = "SELECT * FROM spares WHERE id = ".$row_rs_spares['also_purchased1'];

I want to say where the id is equal to $row_rs_spares['also_purchased1'] or $row_rs_spares['also_purchased2'] or $row_rs_spares['also_purchased3']
SOLUTION
Avatar of alain34
alain34
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ludofulop
ludofulop

$query_rs_spares_also = "SELECT * FROM spares WHERE id IN (".$row_rs_spares['also_purchased1'].", ".$row_rs_spares['also_purchased2'].", ".$row_rs_spares['also_purchased13].")";
SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
If the number of values is not defined you can do:
$query = "SELECT * FROM spares WHERE id IN(".implode(",",$row_rs_spares).")";
Avatar of Pete Winter

ASKER

Thanks you all for your reply, but...

alain34 & leakim971 I get the following error message:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 1

ludofulop

I get a blank page.

Please can you check my code attached.
mysql_select_db($database_conn_tech8, $conn_tech8);
$query_rs_spares_also = "SELECT * FROM spares WHERE id IN(".$row_rs_spares['also_purchased1'].",".$row_rs_spares['also_purchased2'].",".$row_rs_spares['also_purchased3'].")";
$rs_spares_also = mysql_query($query_rs_spares_also, $conn_tech8) or die(mysql_error());
$row_rs_spares_also = mysql_fetch_assoc($rs_spares_also);
$totalRows_rs_spares_also = mysql_num_rows($rs_spares_also);

Open in new window

ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks Leakim971 My error occurred when of the variables was null.
You're welcome! Thanks for the points!