onefitchick Posted January 10, 2010 Share Posted January 10, 2010 Hello. I would like to order by ascending States, then Cities, then Gyms in the following code, but I can't figure it out. If anyone could help, I would truly appreciated it! if(isset($countryid)) { $sql = "Select * from ".TBGYM." G LEFT JOIN ".TBCITIES." CT ON G.cityid= CT.id LEFT JOIN ".TBSTATES." S ON CT.sid=S.id LEFT JOIN ".TBCOUNTRY." C ON S.cid=C.countries_id WHERE G.countryid=".$countryid; } if(isset($stateid)) { $sql = "Select * from ".TBGYM." G LEFT JOIN ".TBCITIES." CT ON G.cityid= CT.id LEFT JOIN ".TBSTATES." S ON CT.sid=S.id LEFT JOIN ".TBCOUNTRY." C ON S.cid=C.countries_id WHERE G.stateid=".$stateid; } if(isset($cityid)) { $sql = "Select * from ".TBGYM." G LEFT JOIN ".TBCITIES." CT ON G.cityid= CT.id LEFT JOIN ".TBSTATES." S ON CT.sid=S.id LEFT JOIN ".TBCOUNTRY." C ON S.cid=C.countries_id WHERE G.cityid=".$cityid; } $pager = new PS_Pagination($db, $sql, $noofrecords,$noofnavigators, "param1=valu1¶m2=value2"); $pager->setDebug(true); $rs = $pager->paginate(); if(!$rs) die(mysql_error()); while($row = mysql_fetch_assoc($rs)) { $arr_result [] = $row; } Link to comment https://forums.phpfreaks.com/topic/187925-help-with-order-by/ Share on other sites More sharing options...
sasa Posted January 10, 2010 Share Posted January 10, 2010 add 'ORDER BY States, Cities, Gyms' after WHERE part of your SQL Link to comment https://forums.phpfreaks.com/topic/187925-help-with-order-by/#findComment-992237 Share on other sites More sharing options...
onefitchick Posted January 10, 2010 Author Share Posted January 10, 2010 Thanks for the help but still can't figure it out. This is what I did, but now when I go to my site, it says there are no countries, states, cities, gyms that match anything. if(isset($countryid)) { $sql = "Select * from ".TBGYM." G LEFT JOIN ".TBCITIES." CT ON G.cityid= CT.id LEFT JOIN ".TBSTATES." S ON CT.sid=S.id LEFT JOIN ".TBCOUNTRY." C ON S.cid=C.countries_id WHERE G.countryid= .$countryid ORDER BY name, cityname, gymname"; } if(isset($stateid)) { $sql = "Select * from ".TBGYM." G LEFT JOIN ".TBCITIES." CT ON G.cityid= CT.id LEFT JOIN ".TBSTATES." S ON CT.sid=S.id LEFT JOIN ".TBCOUNTRY." C ON S.cid=C.countries_id WHERE G.stateid= .$stateid ORDER BY name, cityname, gymname"; } if(isset($cityid)) { $sql = "Select * from ".TBGYM." G LEFT JOIN ".TBCITIES." CT ON G.cityid= CT.id LEFT JOIN ".TBSTATES." S ON CT.sid=S.id LEFT JOIN ".TBCOUNTRY." C ON S.cid=C.countries_id WHERE G.cityid= .$cityid ORDER BY name, cityname, gymname"; } Link to comment https://forums.phpfreaks.com/topic/187925-help-with-order-by/#findComment-992266 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.