David
David

Reputation: 43

mysql output sort order

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/

Upvotes: 0

Views: 95

Answers (3)

Linga
Linga

Reputation: 10553

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;

Upvotes: 1

KethanKumar
KethanKumar

Reputation: 726

Try this:

count(*) returns only count. FOR EXAMPLE

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

Upvotes: 0

Satish Sharma
Satish Sharma

Reputation: 9635

try it

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

Upvotes: 0

Related Questions