1

I can select everything from my db but i want to select everything that has a condition (which is a field in the table) of new or used but seemingly am doing something wrong:

$query = "SELECT * FROM caravandb WHERE condition='New' OR condition='Used' ORDER BY price DESC";

Anyone able to shed light on where i am going wrong?

$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>";
}
3
  • What happens when you run that query? Does it fail? Does it return the wrong data? Commented Aug 21, 2013 at 15:44
  • it fails: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource Commented Aug 21, 2013 at 15:45
  • it would also be useful if you could show the table schema Commented Aug 21, 2013 at 15:48

1 Answer 1

2
"SELECT * FROM caravandb WHERE `condition`='New' OR `condition`='Used' ORDER BY price DESC"

Condition is a reserved word.http://dev.mysql.com/doc/refman/5.0/en/reserved-words.html

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.