CorkyMcDoogle Posted August 9, 2006 Share Posted August 9, 2006 Hello...I'm trying to set up a way to sort database results by the type of article it is. I have links Show: Type1 - Type2 - Type3 - All. The single type links work correctly but when I want to show all of them together nothing comes back. It's because the syntax I'm using is not correct I'm guessing.Whats the correct way to ask for multiple types in the WHERE?[code]switch ($_GET['type']){ case 'type1': $type = "type1"; break; case 'type2': $type = "type2"; break; case 'type3': $type = "type3"; break; case 'typ4': $type = "type4"; break; case 'all': $type = "type1,type2,type3,type4"; break; }}else {$type = "type1";}$query = "SELECT DISTINCT type, title, itemtext, DATE_FORMAT(postdate,'%b %D, %Y - %l:%i %p') AS postdate FROM item WHERE type = ('$type') ORDER BY rand() LIMIT 10";[/code] Quote Link to comment https://forums.phpfreaks.com/topic/17041-proper-syntax-for-where-in-query/ Share on other sites More sharing options...
onlyican Posted August 9, 2006 Share Posted August 9, 2006 SELECT * FROM table WHERE fieldname = 'text';orSELECT * FROM table WHERE fieldname LIKE '%text%';Hope this helps Quote Link to comment https://forums.phpfreaks.com/topic/17041-proper-syntax-for-where-in-query/#findComment-71929 Share on other sites More sharing options...
CorkyMcDoogle Posted August 9, 2006 Author Share Posted August 9, 2006 Yea but I'm trying to get multiple types into one WHERE.If type is set to 'all' I want it to show all types. Something like...[code]WHERE type = 'type1 OR type2 OR type3 OR type4'[/code]How can I make what I want fit into the $type variable? Quote Link to comment https://forums.phpfreaks.com/topic/17041-proper-syntax-for-where-in-query/#findComment-71952 Share on other sites More sharing options...
sasa Posted August 9, 2006 Share Posted August 9, 2006 [code]WHERE type = 'type1' OR type = 'type2' OR type = 'type3' etc.[/code]or[code]WHERE type IN ('type1','type2','type3','type4')[/code] Quote Link to comment https://forums.phpfreaks.com/topic/17041-proper-syntax-for-where-in-query/#findComment-71962 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.