1

我可以从我的数据库中选择所有内容,但我想选择具有新的或使用的条件(表中的一个字段)但似乎做错了什么的所有内容:

$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 />&pound;" . 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>";
}
4

1 回答 1

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

于 2013-08-21T15:52:37.380 回答