SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Guru coiL's Avatar
    Join Date
    Sep 2001
    Location
    QLD, Australia
    Posts
    666
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Changing order of data displayed on a web page

    First, I'm sorry if this is in the wrong place, I am only assuming that what I want to do is done in php..

    Ok so what I want to do is have a list that you can change the order of with a click of the button (on a web page). So for example I have a list of 50 books with different titles by different authors and published in different years. I want to be able to give users the option to display the list in order or author or book title or publishing date.

    I know that I will need mysql for all the data in the list (right?) and am pretty sure that I can figure out how to do that part .. but how do I get the info to show in different orders .. ?

    ps. I don't know any php
    coiL
    "cradled in the learning curve"

  2. #2
    SitePoint Zealot
    Join Date
    Dec 2001
    Location
    Canada
    Posts
    174
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It would be fairly easy. Once you had your Select query to get the data from mysql you would just use the ORDER BY function and have each field linked to a SQL query that will order by that particular field.

  3. #3
    SitePoint Wizard silver trophy TheOriginalH's Avatar
    Join Date
    Aug 2000
    Location
    Thailand
    Posts
    4,810
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $order=$_GET['order'];

    if (
    $order="title") {
    $sql "SELECT title, author, year FROM books ORDER by title ASC";
    }

    if (
    $order="author") {
    $sql "SELECT title, author, year FROM books ORDER by author ASC";
    }

    if (
    $order="year") {
    $sql "SELECT title, author, year FROM books ORDER by year ASC";

    Would be one way
    ~The Artist Latterly Known as Crazy Hamster~
    922ee590a26bd62eb9b33cf2877a00df
    Currently delving into Django, GIT & CentOS

  4. #4
    SitePoint Zealot
    Join Date
    Dec 2001
    Location
    Canada
    Posts
    174
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    exactly, I just couldnt be bothered to write the code.

  5. #5
    SitePoint Wizard silver trophy TheOriginalH's Avatar
    Join Date
    Aug 2000
    Location
    Thailand
    Posts
    4,810
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    I, er, had my secretary do it...
    ~The Artist Latterly Known as Crazy Hamster~
    922ee590a26bd62eb9b33cf2877a00df
    Currently delving into Django, GIT & CentOS

  6. #6
    Weird Little Girl Desdelena's Avatar
    Join Date
    May 2002
    Location
    Canada
    Posts
    266
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I know this is an old thread but it deals with my problem so I thought Id reply instead of start another. Ive used auto_increment and I want to display the HIGHEST numbered id first. How do I do that?
    Memento Mori

  7. #7
    ********* Celica Lover Coomer's Avatar
    Join Date
    Apr 2002
    Location
    Not worth the drive
    Posts
    474
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by Desdelena
    I know this is an old thread but it deals with my problem so I thought Id reply instead of start another. Ive used auto_increment and I want to display the HIGHEST numbered id first. How do I do that?
    Just do this:

    PHP Code:
    SELECT FROM your_table ORDER BY your_auto_increment_id DESC
    + Celica =
    6G Celicas :: My '94-99 Toyota Celica resource

  8. #8
    Weird Little Girl Desdelena's Avatar
    Join Date
    May 2002
    Location
    Canada
    Posts
    266
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Whats "your_auto_increment_id" supposed to be?

    <edit>Oh nevermind, its just the name of the column that auto_increments. Thanks I got it!
    Memento Mori


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
  •