2010-12-18 55 views
1
<?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); 
?> 
+0

告诉您的查询按日期排序...? – BoltClock 2010-12-18 08:18:44

回答

1

只需添加ORDER BY date到您的SQL查询=)

2

改变你的SQL这样的:

SELECT * FROM testimonial where approved='Yes' ORDER BY date LIMIT $offset, 10 
               ^^^^^^^^^^^^^ 
+0

谢谢大家...; p – 2010-12-18 08:22:26

2

MySQL有一个ORDER BY的内置功能。

$result = mysql_query ("SELECT * FROM testimonial where approved='Yes' ORDER BY date LIMIT $offset, 10");