How to use order by in here

Discussion in 'PHP' started by baris22, Sep 9, 2010.

  1. #1
    hi all,

    I need to display all the countries and the current country should come first. How should i do this?

    
    
    $sql = "SELECT * FROM $countries WHERE countryid = $country[countryid] AND enabled = '1' $sort2";
    
    
    PHP:
    thanks all
     
    baris22, Sep 9, 2010 IP
  2. wd_2k6

    wd_2k6 Peon

    Messages:
    1,740
    Likes Received:
    54
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Hi,

    What do you mean exactly you just want the current countryid at the top of the list and the rest of the ordering doesn't matter?
    If so just use 2 queries display the current country in the first one and use the 2nd query to display the rest.

    What is $sort2 out of interest?
     
    wd_2k6, Sep 9, 2010 IP
  3. baris22

    baris22 Active Member

    Messages:
    543
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    60
    #3
    thanks for your help. sorted.

    
    
    ORDER BY countryname like '$xcountryname%' desc
    
    
    PHP:
     
    baris22, Sep 9, 2010 IP
  4. SEOaaron

    SEOaaron Peon

    Messages:
    107
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    ORDER BY just refers to the table row value youre after the ordering by, 'desc' can be appended to change it to descending
     
    SEOaaron, Sep 9, 2010 IP