Sorting Movies By 2 Things

后端 未结 4 1065
广开言路
广开言路 2021-01-26 04:32

Hay everyone need abit of help i a noob when it come to php :(

In my database i have a table called movies and i have 12 columns in there but i used 2 collumns for sorti

相关标签:
4条回答
  • 2021-01-26 04:50

    Just seperate the order columns by a comma.

    $order = "ORDER BY imdb_rating, year DESC";
    

    You should definitely consider to use another MySQL extension as well, mysql_* is deprecated, use mysqli_* or PDO. I prefer PDO.

    0 讨论(0)
  • 2021-01-26 04:56

    Just separate the columns with commas:

    elseif($sortby == 'imdb_rating and year')
    {
        $order = 'ORDER BY `imbd_rating`, `year` DESC';
    }
    

    Alternatively, if you'd like to order them differently (for example by year and then rating), use:

    ORDER BY `year` DESC, `imdb_rating` ASC
    

    It's also worth noting that the mysql_* set of function is now deprecated. It'd be better to use MySQLi or PDO.

    0 讨论(0)
  • 2021-01-26 05:12

    You have to change the syntax slightly.

    "ORDER BY imdb_rating DESC, year DESC";
    
    0 讨论(0)
  • 2021-01-26 05:15

    Replace and with a simple comma:

    ORDER BY imdb_rating DESC, year DESC
    
    0 讨论(0)
提交回复
热议问题