SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Member
    Join Date
    Mar 2005
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Sorting Data Alphabetically

    I have a list of data stored in a mysql database. My problem is that I want to display the the list of information alphabetically and also by date using PHP. How do you do this?

  2. #2
    SitePoint Zealot dhantiflag's Avatar
    Join Date
    Mar 2005
    Location
    Mentor, oh
    Posts
    158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    http://www.sitepoint.com/forums/showthread.php?t=241822

    let me kno if this helps you at all

  3. #3
    SitePoint Member
    Join Date
    Mar 2005
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I want to sort the data using PHP not mySQL database, but thanks anyway.

  4. #4
    chown linux:users\ /world Hartmann's Avatar
    Join Date
    Aug 2000
    Location
    Houston, TX, USA
    Posts
    6,455
    Mentioned
    11 Post(s)
    Tagged
    0 Thread(s)
    Can I ask why you want to do it in PHP and not MySQL? Doing this type of operation in MySQL (during the query) is a lot more efficient than using PHP code to do it. The simple lines in MySQL will achieve the desired result and the query and sorting take place in a single query instead of query, get result set, then sort.
    Last edited by Hartmann; May 25, 2005 at 09:28.

  5. #5
    Level 8 Chinese guy Archbob's Avatar
    Join Date
    Sep 2001
    Location
    Somewhere in this vast universe
    Posts
    3,741
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Your going to have to create a temporary array and then go through a sort algorithem and store the values of the original array in the temp.

    yeah, doing it in mysql is much easier and more efficient.

  6. #6
    SitePoint Member
    Join Date
    Mar 2005
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you sort the data in mysql will it automatically sort new data when it is entered in the database or would you have tell the database to alphabetize the data when new data is entered.

  7. #7
    chown linux:users\ /world Hartmann's Avatar
    Join Date
    Aug 2000
    Location
    Houston, TX, USA
    Posts
    6,455
    Mentioned
    11 Post(s)
    Tagged
    0 Thread(s)
    Everytime the data is entered and you go to the page where you can see the data it will be organized alphabetically.


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
  •