Hello,
I have a database that has several columns...one being BUSINESS NAME, another CATEGORY and a third of CATEGORY2- along with some others. I would like to have a dropdown menu that would list all of the CATEGORY and CATEGORY2 entries together without any repeats of categories.
Here is an example of what the database would look like:
BUSINESS | CATEGORY | CATEGORY2
Joe's Shoes | Clothing | -
Ace Photography |Photography |Graphic Design
Sue's Designs |Graphic Design | -
So the dropdown (in alphabetical order) would look like this:
Clothing
Graphic Design
Photography
Now if someone selected Graphic Design they would get a search result that listed both businesses in the database and their contact information. Here is what I have so far but am getting an error: "You have an error in your SQL syntax near 'DISTINCT category2 FROM table ORDER BY category' at line 1"
<?
$sql = "SELECT DISTINCT category, DISTINCT category2 FROM table ORDER BY category";
$result = mysql_query($sql) or die($sql . '<br />' . mysql_error());
echo '<form method="POST" action="results.php">';
echo '<select name="category_search">';
while ($row = mysql_fetch_array($result)) {
echo '<option value="' . $row['category'] . '">' . $row['category'] . '</option>';
echo '<option value="' . $row['category2'] . '">' . $row['category2'] . '</option>';
}
echo '</select>';
echo ' <input type="Submit" name="Submit" value="Submit"></form></table>';
?>
Any ideas on how I can resolve this? Thanks in advance!