dongyanzhui0524 2014-01-25 07:21
浏览 89

mysql输出排序顺序

I am using a PHP / MySQL pagination script which works fine, however I have trouble sorting the output accordingly.

Here parts of my script:

        $link=mysql_connect("localhost","x","x");
        mysql_select_db("x",$link);
        $q="select count(*) \"total\"  from entries";
        $ros=mysql_query($q,$link);
        $row=(mysql_fetch_array($ros));
        $total=$row['total'];
        $dis=3;
        $total_page=ceil($total/$dis);
        $page_cur=(isset($_GET['page']))?$_GET['page']:1;
        $k=($page_cur-1)*$dis;

        $q="select * from entries limit $k,$dis";
        $ros=mysql_query($q,$link);
        while($row=mysql_fetch_array($ros))
        {

I've tried to change the line

    $q="select count(*) \"total\"  from entries";

to

    $q="select count(*) \"total\"  from entries id DESC";

however it does not seem to be working correctly.

Anyone has an idea how I can get this fixed and have the items sorted by ID?

Some expert help would be greatly appreciated - thank you very much.

Please find the original script I have in place here: http://allitstuff.com/php-mysql-pagination-script-download/

  • 写回答

3条回答 默认 最新

  • doulang7699 2014-01-25 07:23
    关注

    The coury

    select count(*) \"total\"  from entries
    

    only returns the count. You can get only the total number of rows.

    If you want to retrieve data please change your query.

    If you want to manipulate with the count only, then try

    $row=mysql_fetch_row($ros);
    $total=$row[0];
    

    Edit:

    The OP want to sort the entries in a reverse order. So try

    select column_name from entries order by column_name desc;
    
    评论

报告相同问题?