I have multiple select boxes that I am using to query a MySQL database. I have the 2 select boxes working. The 2 boxes are not dynamic and I can choose, say Operator from the first box, and Field from the second box, and I get the appropriate results from my query. The problem I am having is that I don't always want to chose something from each box. If I choose something from the Operator box and nothing from the second box, I want to get just Opeator results. In both the select boxes, you have to choose a value.
I hope that makes sense. It is probably something easy.
Here is the code:
<?php
include ('connection.php');
?>
<table border=1 align = center>
<tr><td CLASS=tbltitle><b><center>Operator Name</center></b></td></tr>
<tr><td>
<?
// Query to populate Operator select box //
$queryOp = "SELECT CoNo,CoName FROM tblRefCompany WHERE Stat = 'A' ORDER BY Coname";
$resultOp = mysql_db_query($dbname, $queryOp)
or die ("Couldn't execute query.");
/* create form containing selection list */
echo "<center><form action='jsopoutput2.php' method='post'></center>
<center><select name='CoNo'></center>\n";
while ($rowOp = mysql_fetch_array($resultOp))
{
extract($rowOp);
echo "<center><option value='$CoNo'>$CoName \n";
}
echo "</select>\n";
?>
<tr><td CLASS=tbltitle><b><center>Field Name</center></b></td></tr>
<tr><td>
<?
// Query to populate Field select box //
$queryFld = "SELECT St_FldNo,Name FROM tblGeoFields ORDER BY Name";
$resultFld = mysql_db_query($dbname, $queryFld)
or die ("Couldn't execute query.");
/* create form containing selection list */
echo "<center><select name='St_FldNo'></center>\n";
while ($rowFld = mysql_fetch_array($resultFld))
{
extract($rowFld);
echo "<center><option value='$St_FldNo'>$Name \n";
}
echo "</select>\n";
echo "<tr><td><center><input type='submit' value='Search'></center></td></tr>
</form>\n";
mysql_close ($link);
?>