Jump to content

[SOLVED] multiple where usage


Crusader

Recommended Posts

The basic query looks like this: "select * from table where column1=$value1 and column2=$value2 limit 1"

There would be multiple values of $value1 and $value2 but I'd like to be able to call them all in one mysql_query rather than using a whole set of them then I'd like to output them.

How would I do this?

Thanks.

Link to comment
Share on other sites

[code=php:0]select * from table where column1 IN ($value1, $value2) and column2 IN ($value3, $value4) limit 1[/code]


That'll work if you want all combinations of all values.  If you want only matching combinations, then I think you will need to do it the hard way:

[code=php:0]select * from table where (column1 = $value1 and column2 = $value2) or ($column1 = $value3 and column2 = $value4) or ...[/code]
Link to comment
Share on other sites

[code] $xP=($x-1);
$yP=($y-1);
$xN=($x+1);
$yN=($y+1);
$cX=$xP;
$cY=$yP;[/code]

Your second solution looks like the best one to use for my case but I'm not quite sure on how to implement it. $value1 would be $cX and $value2 would be $cY. The values are incremented but I guess I could make an array for both of the values to make it work.

select * from table where (column1 = $value1[1] and column2 = $value2[1]) or (column1 = $value1[2] and column2 = $value2[1]) or ...

How would I output the results?

e.g. the results for $value1[1] and $value2[2] are true but the results for $value1[2] and $value2[2] are false.

Thanks again.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.