0

I am not able to sort my data according to date

<a href="#"><?php 
                $sql="select link from links ORDER by 'date' DESC";
                mysql_select_db('zealiant');
                $retval = mysql_query( $sql, $conn );
                if(! $retval ) {
                    die('Could not get data: ' . mysql_error());
                }
                while($row = mysql_fetch_array($retval, MYSQL_ASSOC)) {
                    echo "{$row['link']} <br>";
                }
                mysql_close($conn);
            ?></a>
Jay Blanchard
  • 34,243
  • 16
  • 77
  • 119
Priya
  • 1
  • 3
    FYI, [you shouldn't use `mysql_*` functions in new code](http://stackoverflow.com/questions/12859942/). They are no longer maintained [and are officially deprecated](https://wiki.php.net/rfc/mysql_deprecation). See the [red box](http://php.net/manual/en/function.mysql-connect.php)? Learn about [*prepared statements*](https://en.wikipedia.org/wiki/Prepared_statement) instead, and use [PDO](http://php.net/pdo) or [MySQLi](http://php.net/mysqli) - [this article](http://php.net/manual/en/mysqlinfo.api.choosing.php) will help you decide which one is best for you. – John Conde Aug 10 '17 at 17:49
  • don't use single quote for columns name eventually use backtics select link from links ORDER by date DESC – ScaisEdge Aug 10 '17 at 17:55
  • You are not sorting by the `date` column but by the `'date'` string. This renders all the records equal (for the sorting purpose) and their order in the resultset is indeterminate. Use backticks (``) to enclose object names (tables, columns, indexes etc.) – axiac Aug 10 '17 at 18:14

0 Answers0