Sorting MYSQL results...

Discussion in 'MySQL' started by adamiscool, Jul 14, 2008.

  1. #1
    Hi!

    I have a php script that fetches information from a MYSQL database. At the moment the results are sorted by the newest first. I want the user to be able to select how they want to sort the results using a drop down menu. I want the user to be able to sort using these columns name, url, tag and by id.

    At the moment this is the code to sort it:

    $result = mysql_query("SELECT * FROM sites where approved = '1' order by id desc limit $alt,$max");
    $resulttot = mysql_query("SELECT * FROM sites where approved = '1' order by id desc");
    $count = mysql_num_rows($resulttot);
    while($row = mysql_fetch_array($result))

    Thanks so much!!!!!

    Adam
    :)
     
    adamiscool, Jul 14, 2008 IP
  2. adultwordpressthemes

    adultwordpressthemes Active Member

    Messages:
    102
    Likes Received:
    2
    Best Answers:
    1
    Trophy Points:
    83
    #2
    you will have to set a function to do this

    like

    
    
    function sort($arg) {
    
    $result = mysql_query("SELECT * FROM sites where approved = '1' order by '$arg');
    
    }
    
    
    PHP:
     
    adultwordpressthemes, Jul 14, 2008 IP