Jump to content

Help with adding ORDER BY after array!??!


suess0r

Recommended Posts

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

[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
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.