<?php
// create query
$query = "SELECT top 8 * FROM xss_news order by $id desc"; // execute query
$result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); // see if any rows were returned
if (mysql_num_rows($result) > 0) {
// yes
// print them one after another
echo "<table cellpadding=10 border=1>";
while($row = mysql_fetch_row($result)) {
echo "<tr>";
echo "<td>".$row[0]."</td>";
echo "<td>".$row[1]."</td>";
//echo "<td>".$row[2]."</td>";
//echo "<td>".$row[3]."</td>";
echo "</tr>";
}
echo "</table>";
}
else {
// no
// print status message
echo "没有信息!";
} // free result set memory
mysql_free_result($result); // close connection
mysql_close($connection); ?>
// create query
$query = "SELECT top 8 * FROM xss_news order by $id desc"; // execute query
$result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); // see if any rows were returned
if (mysql_num_rows($result) > 0) {
// yes
// print them one after another
echo "<table cellpadding=10 border=1>";
while($row = mysql_fetch_row($result)) {
echo "<tr>";
echo "<td>".$row[0]."</td>";
echo "<td>".$row[1]."</td>";
//echo "<td>".$row[2]."</td>";
//echo "<td>".$row[3]."</td>";
echo "</tr>";
}
echo "</table>";
}
else {
// no
// print status message
echo "没有信息!";
} // free result set memory
mysql_free_result($result); // close connection
mysql_close($connection); ?>
这个ASP的写法$query="select * from xss news order by $id desc limit0,8";
select *from vc3 limit StartPos, number;
StartPos :开始位置(从零开始计算)
Number :取多少位。
top 不是mysql 的关键字。
写程序的时候请确保sql语句是否正确。
建议:先echo出sql语句 执行下对不对