I have two pages and a database. The database has 'business' which is the business name and 'category' which is the business category. The first php page is a search page (which is basically a form) and the second is a results page. Here is what the results page looks like...
<?
//connect to mysql
//change user and password to your mySQL name and password
mysql_connect("host","user","password");
//select which database you want to edit
mysql_select_db("database");
$search=$_GET["search"];
if (isset($GET['search'])) {$search = $GET['search'];}
else {$search = '';}
if (!$search)
{
echo 'Please Input Something To Search For';
}
elseif (strlen($search) < 3)
{
echo 'Please Enter At Least Three Characters';
}
else
{
//get the mysql and store them in $result
//change whatevertable to the mysql table you're using
//change whatevercolumn to the column in the table you want to search
$result = mysql_query("SELECT * FROM table WHERE business LIKE '%$search%'");
//grab all the content
while($r=mysql_fetch_array($result))
{
//the format is $variable = $r["nameofmysqlcolumn"];
//modify these to match your mysql table columns
$business=$r["business"];
$category=$r["category"];
//display the row
echo "<strong>$business</strong><br> <u>Category</u>: $category <br><br>";
}
}
?>
This allows me to type in keywords of a business name which will query the database showing me the business name and category of that business that matched the keywords from the search.php page on the results.php page.
What I would like to do is instead of a keyword search is to have a drop down menu that lists all of the categories in the database, which one would select and then submit, to show all the businesses that have that particular category shown on the results.php page.
I would also like the categories in the drop down list to be alphabetical and only show one category for each category...in other words if there are three businesses that have a category of 'cleaning supplies' that it would only show once in the list instead of once for each business. Any help is appreciated!!!!
Thanks much.