I am having quite a bit of difficulty getting some functions of a multi-functional tool to work. I want to be able to sort by name or catalog number, filter by category, or do an open-ended search. Here is the current code:
$sort = ($_POST['sort']) ? $_POST['sort'] : 'name';
$order = ($_POST['order']) ? $_POST['order'] : 'asc';
if($_POST['Search'])
{
$search = ($_POST['Search']);
$query_compounds = "select * from compounds where name like'%$search%' or catalog_number like'%$search%' or synonyms like'%$search%' or cas_number like'%$search%' or formula_weight like'%$search%' or molecular_formula like'%$search%'";
}
else if($_POST['category']) {
$category = ($_POST['category']);
$query_compounds = "select * from compounds where category = ".$category;
}
else {
$query_compounds = "select * from compounds order by " . $sort . " " . $order;
}
Later in the page, the following code is called upon:
<form name="SortForm" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" style="float:left;">
<select name="sort">
<option <?php if($sort == 'name'){ echo "selected"; }?> value="name">Name</option>
<option <?php if($sort == 'catalog_number'){ echo "selected"; }?> value="catalog_number">Catalog Number</option>
</select>
<select name="order">
<option <?php if($order == 'asc'){ echo "selected"; }?> value="asc">Ascending</option>
<option <?php if($order == 'desc'){ echo "selected"; }?> value="desc">Descending</option>
</select>
<input name="SortForm" type="submit" id="SortForm" value="Sort">
</form>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST" style="float:left;">
<select name="category">
<option <?php if($category == 'Compounds'){ echo "selected"; }?> value="Compounds">Compounds</option>
<option <?php if($category == 'Glucuronides'){ echo "selected"; }?> value="Glucuronides">Glucuronides</option>
<option <?php if($category == 'Metabolites'){ echo "selected"; }?> value="Metabolites">Metabolites</option>
</select>
<input name="category" type="submit" id="category" value="Select">
</form>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="GET" style="float:left;">
<input id="Search" type="text" placeholder="Type here">
<input id="Search" type="submit" value="Search" name="Search">
</form>
Any assistance in this matter would be greatly appreciated.