我可以从我的数据库中选择所有内容,但我想选择具有条件(表中的一个字段)的新内容或已使用的所有内容,但似乎做错了:
$query = "SELECT * FROM caravandb WHERE condition='New' OR condition='Used' ORDER BY price DESC";
任何能够揭示我哪里出错的人都会知道吗?
$caravanquery = "SELECT * FROM caravandb WHERE condition = 'New' OR condition = 'Used' ORDER BY price DESC";
$caravanresult = mysql_query($caravanquery);
while($row = mysql_fetch_array($caravanresult)){
echo "<td width='280' align='center' class='model'>";
echo $row['make'] . " " . $row['model'] . " " . $row['year'];
echo "</td><td width='100'>";
echo "<ul>" . "<li>" . $row['berth'] . " Berth</li>" . "<li>MTPLM: " . $row['mtplm'] . "Kg</li>" . "</ul></td>";
echo "<td width='60' align='center' class='price'>";
echo "<span>" . $row['oldprice'] . "</span>" . "<br />£" . substr($row['price'], 0, -3) . ',' . substr($row['price'], -3);
echo "</td><td width='200' align='right' class='layout'>";
echo "<img src='layouts/".$row['ref'].".gif'>";
echo "</td></tr>";
}
答案 0 :(得分:2)
"SELECT * FROM caravandb WHERE `condition`='New' OR `condition`='Used' ORDER BY price DESC"
条件是保留字。http://dev.mysql.com/doc/refman/5.0/en/reserved-words.html