mysql输出排序顺序

时间:2014-01-25 07:21:33

标签: php mysql

我正在使用PHP / MySQL分页脚本,但是我无法相应地对输出进行排序。

这是我脚本的部分内容:

        $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))
        {

我试图改变这条线

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

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

然而它似乎没有正常工作。

任何人都知道如何解决此问题,并按ID分类项目?

非常感谢一些专家的帮助 - 非常感谢。

请在此处找到我原来的原始脚本:http://allitstuff.com/php-mysql-pagination-script-download/

3 个答案:

答案 0 :(得分:1)

coury

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

仅返回计数。您只能获得总行数。

如果您想检索数据,请更改您的查询。

如果您只想使用计数进行操作,请尝试

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

编辑:

OP希望以相反的顺序对条目进行排序。所以试试

select column_name from entries order by column_name desc;

答案 1 :(得分:0)

试试吧

$q="select count(*) as total  from entries ORDER BY id DESC;";

答案 2 :(得分:0)

试试这个:

count(*)仅返回计数。 FOR EXAMPLE

SELECT column_name1,column_name2,count(*)
FROM table_name
ORDER BY column_name1,column_name2 ASC|DESC;