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
https://forums.phpfreaks.com/topic/30297-solved-multiple-where-usage/
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]
[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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.