PHP/SQL Where, And, Order By -- works on one statement but getting an
error on another similar query
I'm trying to add a section that shows if any year end awards are won by
an individual. I have any Champions and Reserve Champions showing just
fine. However, when I went to add the "year end awards" section I keep
getting this error:
You have an error in your SQL syntax; check the manual that corresponds to
your MySQL server version for the right syntax to use near 'show = yearend
ORDER BY year DESC' at line 1
I have played around with apostrphes, using a LIKE statement, removing the
ORDER BY, and anything I could think of but I am at a loss. I can't seem
to figure out what changed from the working statements that would cause an
error.
This works just fine
<?php
$id = $_GET['id']; //Gets the ID from the URL
$result = mysql_query("SELECT * FROM competition
WHERE id = $id
AND place = 'CH'
ORDER BY year DESC") or die(mysql_error());
while($row = mysql_fetch_array($result)){
echo $row['class'];
echo "<small>(";
echo $row['show'];
echo ")</small><br>";
}
?>
This does not work The only change I made in the below is place = is now
show =
<?php
$id = $_GET['id']; //Gets the ID from the URL
$result = mysql_query("SELECT * FROM competition
WHERE id = $id
AND show = 'yearend'
ORDER BY year DESC") or die(mysql_error());
while($row = mysql_fetch_array($result)){
echo $row['class'];
echo "<br>";
}
?>
No comments:
Post a Comment