Portal Home > Knowledgebase > Articles Database > PHP and Mysql help?
PHP and Mysql help?
Posted by DediPath, 12-06-2007, 06:08 PM |
Ok I'm querying my table for all threads that are owned by a particular board. But the way I'm doing it is selecting all the threads that have a status of 1 or 2
they have to belong to a particular board( $bid )
they have to have a status of 1 or 2.
If anyone has any help or ideas that would be greatly appreciated.
|
Posted by ThatScriptGuy, 12-06-2007, 06:18 PM |
Parentheses are a lifesaver...
SELECT * FROM threads WHERE board='$bid' AND (status='1' OR status='2')
kevin
|
Posted by DediPath, 12-06-2007, 06:35 PM |
Thanks, worked perfectly
Just out of curiosity how can I have more variables, like make sure the status is 1,2,3,4
|
Posted by ThatScriptGuy, 12-06-2007, 06:37 PM |
status='1' OR status='2' OR status='3' OR status='4')
Whatever is executed in parentheses is done first. So, first it checks that the status is 1 or 2 or 3 or 4 and only then does it check that the board is equal to $bid
|
Posted by DediPath, 12-06-2007, 06:46 PM |
ok Thank you
|
Posted by foobic, 12-06-2007, 07:04 PM |
If you're checking a list of options you can also use:
SELECT * FROM threads WHERE board='$bid' AND status IN (1,2,3,4)
|
Add to Favourites Print this Article
Also Read