suess0r Posted January 6, 2007 Share Posted January 6, 2007 hey, OK so i have an array that makes up my SQL query according to what the user has chosen. The problem is that i want to add "ORDER BY orlandofull.club_name" at the end of the SQL statement.. i know sounds kinda odd but i just can't seem to get it ???[quote]$tmpq = array(); $sql= 'SELECT * FROM orlandofull WHERE '; if($city != "") $tmpq[] = 'orlandofull.Club_Landmark = "'.$city.'" '; if($type != "") $tmpq[] .= 'orlandofull.'.$typeList[$type].' = "Yes" '; if($subtype != "") $tmpq[] .= 'orlandofull.'.$subtypeList[$subtype].' = "Yes" '; if($cost != "") $tmpq[] .= 'orlandofull.`'.$cost.'` = "Yes"'; $sql .= implode(' AND ',$tmpq);[/quote] Link to comment https://forums.phpfreaks.com/topic/33111-help-with-adding-order-by-after-array/ Share on other sites More sharing options...
taith Posted January 6, 2007 Share Posted January 6, 2007 you dont need to specify the "orlandofull." just "ORDER BY Club" you only need to specify the table name if your accessing 2 tables at once... Link to comment https://forums.phpfreaks.com/topic/33111-help-with-adding-order-by-after-array/#findComment-154276 Share on other sites More sharing options...
Hypnos Posted January 6, 2007 Share Posted January 6, 2007 [code=php:0]$tmpq = array(); $sql= 'SELECT * FROM orlandofull WHERE'; if($city != "") $tmpq[] = ' orlandofull.Club_Landmark = "'.$city.'"'; if($type != "") $tmpq[] .= ' orlandofull.'.$typeList[$type].' = "Yes"'; if($subtype != "") $tmpq[] .= ' orlandofull.'.$subtypeList[$subtype].' = "Yes"'; if($cost != "") $tmpq[] .= ' orlandofull.`'.$cost.'` = "Yes"'; $sql .= implode(' AND',$tmpq); $sql .= " ORDER BY orlandofull.club_name";[/code]It's important to have your spaces in the right spot. It works best if you have them before each addition to the string, rather than after. Link to comment https://forums.phpfreaks.com/topic/33111-help-with-adding-order-by-after-array/#findComment-154277 Share on other sites More sharing options...
suess0r Posted January 6, 2007 Author Share Posted January 6, 2007 Thanks so much hypnos that's all i was looking for! ;D Link to comment https://forums.phpfreaks.com/topic/33111-help-with-adding-order-by-after-array/#findComment-154286 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.