Reputation: 11
I am working on a search tool using PHP, which is retrieving data from a database. It works, but now I would like to sort the results by the newest date. created
is the name of the column that stores the database time stamp.
Here is the code I have:
$res = mysql_query("SELECT * FROM book WHERE MATCH
(title,cat_number,isbn,issn,created,subject) AGAINST ('$q' $mode) LIMIT 50", $db);
$list = array();
while($row = mysql_fetch_assoc($res))
{
$list[] = $row;
}
mysql_free_result($res);
Upvotes: 1
Views: 164
Reputation: 2051
You can update your query to look like this:
$res = mysql_query("SELECT * FROM book WHERE MATCH (title,cat_number,isbn,issn,created,subject) AGAINST ('$q' $mode) ORDER BY created DESC LIMIT 50", $db);
On another note, you should be using mysqli or PDO over mysql commands, as mysql commands are now deprecated.
Upvotes: 1