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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.