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; } Quote 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 Quote 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"; } Quote Link to comment https://forums.phpfreaks.com/topic/187925-help-with-order-by/#findComment-992266 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.