使用的代码(已建立数据库连接):
<?php
$cur = mysql_query("SELECT MAX(id) FROM trades");
echo "$cur";
while($cur >= 0) {
$query = mysql_query("SELECT * FROM trades WHERE id='$cur'");
if(mysql_num_rows($query)==0) {
echo "ERROR!";
exit();
}
$row = mysql_fetch_assoc($query);
$tradeID = $row['ID'];
$mcUsername = $row['Minecraft Username'];
$blockID = $row['Block ID'];
$quantity = $row['Quantity'];
$costPer = $row['CostPer'];
$tradeNotes = $row['TradeNotes'];
echo "<tr>";
echo "<td class='first-td'>$tradeID</td>";
echo "<td>$mcUsername</td>";
echo "<td>$blockID</td>";
echo "<td>$quantity</td>";
echo "<td>$costPer</td>";
echo "<td class='last-td'>$tradeNotes</td>";
echo "</tr>";
$cur = "$cur - 1";
}
?>
$cur 的回声正在返回:Resource id #7
并且 if 语句正在返回ERROR
,这很可能是由于 $cur 无法正常工作引起的。
我正在做的事情是否存在某种语法错误,因为当我在 MySQL DB 中手动运行 $cur 的 SQL 查询时,它会返回预期值。