Query error..

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
SirChick
Forum Contributor
Posts: 125
Joined: Tue Jul 31, 2007 11:55 am

Query error..

Post by SirChick »

I'm getting this error with my query... not sure how to fix it though....


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 'WHERE C < '3'' at line 1

Code: Select all

<?php
//generates a list box to display the rows of available houses in the soldhouses table depending on which one the user clicks on then clicks buy will be "should be" the one that goes to the session
$CountNames = ("SELECT *, count(BusinessType) as C FROM `businesses` GROUP BY BusinessType WHERE C < '3'");
$findbusinessresult = mysql_query($CountNames) or die(mysql_error());

echo '<br><br><center><select name="businesslist" size=10>">';
		Echo'<option value =""><b><u>Business Types</b></u></option>';
while($row = mysql_fetch_array($findbusinessresult)) {
        echo "<option value=\"{$row['BusinessType']}\">{$row['BusinessType']}</option>";
		}
echo '</select></center>';


?>
What did i do wrong?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

GROUP BY goes after WHERE clauses, not before.
Post Reply