SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict
    Join Date
    Nov 2007
    Posts
    219
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Lightbulb Sorting After Explode

    I have this query which echos the data in the field CODE
    which is like that 1|2|3|4|5 etc
    which is the codes ids for each city


    PHP Code:
    $query="select * from vz_cities_tbl where VCI_ID='".$row_Recordset2['city_of_interest']."' ";
    $result=mysql_query($query);

    if(
    mysql_num_rows($result)>0)
    {
    $city=mysql_fetch_array($result);
                        
    $topBanners=explode('|',$city['CODE']);
                        
    /*print_r($topBanners);
                        
    echo "<br />";*/
                        

    is there any way to sort the Output Descending ???????????
    like
    5|4|3|2|1

  2. #2
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,081
    Mentioned
    153 Post(s)
    Tagged
    2 Thread(s)
    Take a look at The different array sorting functions of PHP and use rsort().

    PHP Code:
    $topBanners=explode('|',$city['CODE']);
    rsort($topBanners); 
    Like it says on the comparison page:

    Note: All of these sort functions act directly on the array variable itself, as opposed to returning a new sorted array
    Rémon - Hosting Advisor

    SitePoint forums will switch to Discourse soon! Make sure you're ready for it!

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  3. #3
    SitePoint Addict
    Join Date
    Nov 2007
    Posts
    219
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yes thank you
    but now the problem that its sorting case sensitive
    as that the sort function is case sensitive. All capital letters come before all lowercase letters

    so is there a way to make it not case sensitive?

    and plz am making a sql statement that search using LIKE
    but its also case sensitive
    like if i search for "Alex" and it was saved as "alex"
    it never shows up!!

    any idea???

  4. #4
    SitePoint Zealot Kayarc's Avatar
    Join Date
    Sep 2009
    Posts
    127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Phoenix Arizona Web Design | info *at* kayarc.com | 602.633.2676

  5. #5
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,081
    Mentioned
    153 Post(s)
    Tagged
    2 Thread(s)
    Quote Originally Posted by Kayarc View Post
    That won't work since natcasesort sorts ascending.

    What would work:
    PHP Code:
    $topBanners=explode('|',$city['CODE']);
    $topBannersLowercase array_map('strtolower'$topBanners');

    array_multisort($topBannersLowercase, SORT_DESC, SORT_STRING, $topBanners); 
    As for the case insensitive LIKE, ever heard of google?
    Rémon - Hosting Advisor

    SitePoint forums will switch to Discourse soon! Make sure you're ready for it!

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •