[英]How to make this code sort by date?
<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("dbsql", $con);
$offset = 0;
$result = mysql_query ("SELECT * FROM testimonial where approved='Yes' limit $offset, 10");
echo "<table border='0'>
<tr><font color='#000099' style='font-size:18px; margin-left:200px;'>Recently Post</font></tr>
<tr>
<th>From</th>
<th width=`400px`> Review</th>
<th>Date</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['full_name'] . "</td>";
echo "<td>" . $row['review'] . "</td>";
echo "<td>" . $row['date'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysql_close($con);
?>
将您的SQL更改为此:
SELECT * FROM testimonial where approved='Yes' ORDER BY date LIMIT $offset, 10
^^^^^^^^^^^^^
MySQL具有ORDER BY内置函数。
$result = mysql_query ("SELECT * FROM testimonial where approved='Yes' ORDER BY date LIMIT $offset, 10");
只需将ORDER BY date
添加到您的SQL查询=)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.