Jump to content

Help with ORDER BY


onefitchick

Recommended Posts

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&param2=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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.