php - 如何使此代码按日期排序?

标签 php mysql

<?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`>&nbsp;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
                                                ^^^^^^^^^^^^^

关于php - 如何使此代码按日期排序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4477270/

相关文章:

php - Paypal IPN : what if the buyer didn't click the return link after payment?

mysql - LOAD DATA LOCAL INFILE 在 MySQL 中只导入一行

javascript - 如何获取帖子总页数?

php - mysql php 条件获取n到n+6之间的记录

php - 计算达到某个查询需要多少行

mysql - sql创建一个组合两个表的 View

mysql datetime索引列 - 不同的查询响应时间

php - 想要在 yii 中保存(false)后将变量传递给 aftersave() 方法

mysql - 简单的 MySQL View 由来自不同表的聚合数据组成

php - 如何在网页中使用session?