I am creating a search form that uses multiple forms to get matching results from a database that contains meat packaging information. I want eventually for users to be able to use forms to search for the width, length, type, shape and description of a package. With only the matching results to be displayed.
Currently I have 3 dropdown boxes and all work and find matching results. Unfortunately they seem to completely override the other form terms (another problem), but I want to add in a "Any" function so users can search for anything without having to give a specific search for all the dropdown boxes everytime limiting the amount of results that will appear.
HTML code:
<body>
<form action="form3.php" method="post">
<label for ="toolcode">Toolcode: </label>
<input type="text" name="term" /><br />
<label for ="delyncode">Delyn code: </label>
<input type="text" name="term" /><br />
<label for ="description">Description: </label>
<input type="text" name="term" /><br />
<label for ="traysize">Traysize: </label>
<input type="text" name="term" /> <br />
<label for ="trayheight">Trayheight: </label>
<input type="text" name="term" /> <br />
<label for ="traywidth">Traywidth: </label>
<input type="text" name="term" /> <br />
<label for ="traydepth">Traydepth: </label>
<input type="text" name="term" /> <br />
<label for="trayrange">Trayrange: </label>
<select name="trayrange">
<option value="Other">--Any--</option>
<option value="BBQ">BBQ</option>
<option value="Dessert">Dessert</option>
<option value="Display">Display</option>
<option value="Meat">Meat</option>
<option value="Microwave">Microwave</option>
<option value="Party">Party</option>
<option value="Salad/Wet Pasta">Salad/Wet Pasta</option>
<option value="Snacks">Snacks</option>
<option value="Standard">Standard</option>
</select>
<label for ="traytype">Traytype: </label>
<select name="traytype">
<option value="Other">--Any--</option>
<option value="Open">Open</option>
<option value="Cavitised">Cavitised</option>
<option value="Lid">Lid</option>
<option value="Tray">Tray</option>
<option value="Coallition">Coallition</option>
<option value="Bowl">Bowl</option>
<option value="Hinge pack">Open</option>
<option value="Pot">Pot</option>
<option value="Base & Lid">Base and Lid</option>
<option value="Rectangular">Rectangular</option>
<option value="Specalist">Specialist</option>
</select><br />
<label for="trayshape">Trayshape: </label>
<select name="trayshape">
<option value="Other">--Any--</option>
<option value="Rectangular">Rectangular</option>
<option value="Oval">Oval</option>
<option value="Square">Square</option>
<option value="Insert">Insert</option>
<option value="Round">Round</option>
<option value="Open">Open</option>
</select><br />
<input type="submit" value="Submit" />
</form>
</body>
The current "Any" option i have above was just a test. It doesn't work, no results get displayed.
PHP code:
<body>
<?php
$con = mysql_connect ("localhost", "root", "");
mysql_select_db ("delyn_db", $con);
if (!$con)
{
die ("Could not connect: " . mysql_error());
}
$varRange = $_POST['trayrange'];
$varType = $_POST['traytype'];
$varShape = $_POST['trayshape'];
$term = mysql_real_escape_string($_POST['term']);
$sql = "SELECT * FROM delyn WHERE toolcode LIKE '%".$term."%' AND delyncode LIKE
'%".$term."%' AND description LIKE '%".$term."%' AND traysize LIKE
'%".$term."%' AND trayheight LIKE '%".$term."%' AND traywidth LIKE
'%".$term."%' AND traydepth LIKE '%".$term."%' AND trayrange LIKE
'%".$varRange."%' AND traytype LIKE '%".$varType."%' AND trayshape LIKE
'%".$varShape."%' ";
$r_query = mysql_query($sql);
while ($row = mysql_fetch_array($r_query))
{
echo '<br /> Delyn code: ' .$row['delyncode'];
echo '<br /> Tool Code: '.$row['toolcode'];
echo '<br /> Description: '.$row['description'];
echo '<br /> Tray range '.$row['trayrange'];
echo '<br /> Tray type: '.$row['traytype'];
echo '<br /> Tray size: '.$row['traysize'];
echo '<br /> Tray height: '.$row['trayheight'];
echo '<br /> Tray width: '.$row['traywidth'];
echo '<br /> Tray depth: '.$row['traydepth'];
echo '<br /> Tray shape: '.$row['trayshape'] . '<br />' . '<br />'; ;
}
?>
</body>
What would I need to add to allow the users to search allowing for any "tray range", "trayshape" and "traytype". This in theory should display results that match the forms that have info entered.
Thanks in advance for anyone who can help.