Reputation: 422
I was working on this where I have 2 variables
And a table with few variables and 2 principal columns that I am going to use for this script
Now What I want it to do is to check if $pmid or $pmid is matching pmid in table or pmid2 any of the variables to match any of these two table columns mentioned Here's My script:
$selectpm = mysql_query("SELECT * FROM pm WHERE pmid=($chat_id OR $chat_id2) AND pmid2=($ chat_id OR $chat_id2)");
Of Course my code is wrong its just how I tough It could work , But I don't know how exactly is supposed to work thanks !
Upvotes: 1
Views: 486
Reputation: 303
Please use:
$selectpm = mysql_query("SELECT * FROM pm WHERE pmid
IN($chat_id,$chat_id2) OR pmid2 IN($chat_id,$chat_id2)");
Upvotes: 3
Reputation: 44844
This is how you can do it
SELECT * FROM pm
WHERE
(
pmid=$chat_id OR pmid= $chat_id2
)
AND (
pmid2 = $chat_id OR pmid2 = $chat_id2
)
$selectpm = mysql_query(
"SELECT * FROM pm
WHERE ( pmid=$chat_id OR pmid= $chat_id2 )
AND (pmid2 = $chat_id OR pmid2 = $chat_id2)");
A better way is to write the query in a variable as
$qry = "SELECT * FROM pm
WHERE
( pmid=$chat_id OR pmid= $chat_id2 )
AND (pmid2 = $chat_id OR pmid2 = $chat_id2)" ;
$selectpm = mysql_query($qry);
Upvotes: 4
Reputation: 6766
You can use the in
clause
SELECT * FROM pm
WHERE pmid in ($chat_id , $chat_id2)
AND pmid2 in ($chat_id , $chat_id2)
Upvotes: 2