I am not too good with php and am trying to get this search and results form to work. I am trying to get the user to be able to search by shape, color, price range, etc. I was only able to let them search for one color and one lab, However, there is more than one shape and lab to choose from. I know i need to use an array for these variable but don't know how to retrieve them in my query. Can anyone help me?
the search form:
<form action="template_search2.php" method="post">
<table width="84%" border="0" align="center" cellspacing="2">
<tr>
<td class="diamond_search_border"><div align="center">
<table width="98%" border="0" align="center" cellspacing="2">
<tr>
<td><div align="center"><img src="images/imgA.gif" width="30" height="30" /></div></td>
</tr>
<tr>
<td><div align="center">Round</div></td>
</tr>
<tr>
<td><div align="center">
<label>
<input type="checkbox" name="searchshape[]" value="Round" class="text_B"/>
</label>
</div></td>
</tr>
</table>
</div></td>
<td class="diamond_search_border"><div align="center">
<table width="98%" border="0" align="center" cellspacing="2">
<tr>
<td><div align="center"><img src="images/imgB.gif" width="30" height="30" /></div></td>
</tr>
<tr>
<td><div align="center">Princess</div></td>
</tr>
<tr>
<td><div align="center">
<input type="checkbox" name="searchshape[]" value="Princess"class="text_B" />
</div></td>
</tr>
</table>
</div></td>
<td class="diamond_search_border"><div align="center">
<table width="98%" border="0" align="center" cellspacing="2">
<tr>
<td><div align="center"><img src="images/imgC.gif" width="30" height="30" /></div></td>
</tr>
<tr>
<td><div align="center">Emerald</div></td>
</tr>
<tr>
<td><div align="center">
<input type="checkbox" name="searchshape[]" value="Emerald" class="text_B" />
</div></td>
</tr>
</table>
</div></td>
<td class="diamond_search_border"><div align="center">
<table width="98%" border="0" align="center" cellspacing="2">
<tr>
<td><div align="center"><img src="images/imgD.gif" width="30" height="30" /></div></td>
</tr>
<tr>
<td><div align="center">Radiant</div></td>
</tr>
<tr>
<td><div align="center">
<input type="checkbox" name="searchshape[]" value="Radiant" class="text_B"/>
</div></td>
</tr>
</table>
</div></td>
<td class="diamond_search_border"><div align="center">
<table width="98%" border="0" align="center" cellspacing="2">
<tr>
<td><div align="center"><img src="images/imgE.gif" width="30" height="30" /></div></td>
</tr>
<tr>
<td><div align="center">Asscher</div></td>
</tr>
<tr>
<td><div align="center">
<input type="checkbox" name="searchshape[]" value="Asscher"class="text_B" />
</div></td>
</tr>
</table>
</div></td>
<td class="diamond_search_border"><div align="center">
<table width="98%" border="0" align="center" cellspacing="2">
<tr>
<td><div align="center"><img src="images/imgF.gif" width="30" height="30" /></div></td>
</tr>
<tr>
<td><div align="center">Oval</div></td>
</tr>
<tr>
<td><div align="center">
<input type="checkbox" name="searchshape[]" value="Oval" class="text_B"/>
</div></td>
</tr>
</table>
</div></td>
<td class="diamond_search_border"><div align="center">
<table width="98%" border="0" align="center" cellspacing="2">
<tr>
<td><div align="center"><img src="images/imgG.gif" width="30" height="30" /></div></td>
</tr>
<tr>
<td><div align="center">Marquise</div></td>
</tr>
<tr>
<td><div align="center">
<input type="checkbox" name="searchshape[]" value="Marquise" class="text_B"/>
</div></td>
</tr>
</table>
</div></td>
<td class="diamond_search_border"><div align="center">
<table width="98%" border="0" align="center" cellspacing="2">
<tr>
<td><div align="center"><img src="images/imgH.gif" width="30" height="30" /></div></td>
</tr>
<tr>
<td><div align="center">Heart</div></td>
</tr>
<tr>
<td><div align="center">
<input type="checkbox" name="searchshape[]" value="Heart" class="text_B"/>
</div></td>
</tr>
</table>
</div></td>
<td class="diamond_search_border"><div align="center">
<table width="98%" border="0" align="center" cellspacing="2">
<tr>
<td><div align="center"><img src="images/imgI.gif" width="30" height="30" /></div></td>
</tr>
<tr>
<td><div align="center">Pear</div></td>
</tr>
<tr>
<td><div align="center">
<input type="checkbox" name="searchshape[]" value="Pear" class="text_B"/>
</div></td>
</tr>
</table>
</div></td>
<td class="diamond_search_border"><div align="center">
<table width="98%" border="0" align="center" cellspacing="2">
<tr>
<td><div align="center"><img src="images/imgJ.gif" width="30" height="30" /></div></td>
</tr>
<tr>
<td><div align="center">Trillian</div></td>
</tr>
<tr>
<td><div align="center">
<input type="checkbox" name="searchshape[]" value="Trillian" class="text_B"/>
</div></td>
</tr>
</table>
</div></td>
<td class="diamond_search_border"><div align="center">
<table width="98%" border="0" align="center" cellspacing="2">
<tr>
<td><div align="center"><img src="images/imgK.gif" width="30" height="30" /></div></td>
</tr>
<tr>
<td><div align="center">Cushion</div></td>
</tr>
<tr>
<td><div align="center">
<input type="checkbox" name="searchshape[]" value="Cushion" class="text_B"/>
</div></td>
</tr>
</table>
</div></td>
</tr>
</table>
<hr align="center" width="200" noshade="noshade" color="#003333" />
<table width="94%" border="0" align="center" cellspacing="2">
<tr>
<td width="28%" class="text_A"><div align="center">Price Range: </div></td>
<td width="28%" class="text_A"><div align="center">Carats</div></td>
<td width="23%" class="text_A"><div align="center">Color</div></td>
<td width="21%" class="text_A"><div align="center">Clarity</div></td>
</tr>
<tr>
<td><div align="center">
<label>
<input name="searchpricefrom" type="text" size="6" class="text_B"/>
</label>
to
<input name="searchpriceto" type="text" size="6" class="text_B"/>
</div></td>
<td><div align="center">
<label>
<input name="searchcaratsfrom" type="text" size="6" class="text_B"/>
</label>
to
<input name="searchcaratsfrom" type="text" size="6" class="text_B"/>
</div></td>
<td><div align="center">
<select name="colorfrom" class="text_B">
<option>D</option>
<option>E</option>
<option>F</option>
<option>G</option>
<option>H</option>
<option>I</option>
<option>J</option>
<option>K</option>
<option>L</option>
<option>M</option>
<option>N</option>
</select>
to
<select name="colorto" class="text_B">
<option>D</option>
<option>E</option>
<option>F</option>
<option>G</option>
<option>H</option>
<option>I</option>
<option>J</option>
<option>K</option>
<option>L</option>
<option>M</option>
<option>N</option>
</select>
</div></td>
<td><div align="center">
<select name="searchclarityfrom" class="text_B">
<option>FL</option>
<option>IF</option>
<option>VVS1</option>
<option>VVS2</option>
<option>VS1</option>
<option>VS2</option>
<option>SI1</option>
<option>SI2</option>
<option>SI3</option>
<option>I1</option>
<option>I2</option>
<option>I3</option>
</select>
to
<select name="searchclarityto" class="text_B">
<option>FL</option>
<option>IF</option>
<option>VVS1</option>
<option>VVS2</option>
<option>VS1</option>
<option>VS2</option>
<option>SI1</option>
<option>SI2</option>
<option>SI3</option>
<option>I1</option>
<option>I2</option>
<option>I3</option>
</select>
</div></td>
</tr>
</table>
<hr align="center" width="200" noshade="noshade" color="#003333" />
<table width="489" border="0" align="center" cellspacing="2">
<tr>
<td width="34" class="text_A"><div align="right">Lab: </div></td>
<td width="64" class="diamond_search_border"><div align="center">
<input type="checkbox" name="searchlab" value="EGL" class="text_B" id="lab"/>
EGL</div></td>
<td width="66" class="diamond_search_border"><div align="center">
<input type="checkbox" name="searchlab" value="AGS" class="text_B" id="lab"/>
AGS</div></td>
<td width="77" class="diamond_search_border"><div align="center">
<input type="checkbox" name="searchlab" value="GIA" class="text_B" id="lab"/>
GIA</div></td>
<td width="74" class="diamond_search_border"><div align="center">
<input type="checkbox" name="searchlab" value="IGI" class="text_B" id="lab"/>
IGI</div></td>
<td width="74" class="diamond_search_border"><div align="center">
<input type="checkbox" name="searchlab" value="HRD" class="text_B" id="lab"/>
HRD</div></td>
<td width="70" class="diamond_search_border"><div align="center">
<input type="checkbox" name="searchlab" value="Own" class="text_B" id="lab" />
Own</div></td>
</tr>
</table>
<p>
<input name="submit" type="submit" class="text_A" value="Search" />
</p>
</form>
the results page:
<?php
/*set varibles from form */
$searchshape[] = trim ($searchshape);
$searchshapetwo = trim ($searchshapetwo);
$searchlab = trim ($searchlab);
$searchshape = array("Round","Princess");
#
/* connects to database */
@ $dbconn = new mysqli('MYSQL01', 'websightprojects', 'brow51', 'websightprojects');
if (mysqli_connect_errno())
{
echo 'Error: Could not connect to database. Please try again later.';
exit;
}
/*query the database*/
$query = "select * from diamond where shape like '%".$searchshape."%' AND lab like '%".$searchlab."%' ";
$result = $dbconn->query($query);
echo "<table width='98%' border='0' cellspacing='0' bordercolor='#000000' class='main'>
<tr class='results_brder'><td width='8%' class='text_A'>ID#</td>";
echo "<td width='8%' class='text_A'>Shape</td>";
echo "<td width='8%' class='text_A'>Carat</td>";
echo "<td width='8%' class='text_A'>Color</td>";
echo "<td width='8%' class='text_A'>Clarity</td>";
echo "<td class='text_A'><div align='center'>Measurements</div></td>";
echo "<td width='8%' class='text_A'><div align='center'>Lab</div></td>";
echo "<td width='8%' class='text_A'>Price/ct</td>";
echo "<td width='8%' class='text_A'>Price</td>";
echo "<td width='5%' class='text_A'>%Rap</td>";
echo "<td width='8%' class='text_A'><div align='right'>Details</div></td> </tr><br>";
//echo '<p>There are :'.$num_results.' results.</p>';/*number of rows found*/
$num_results = $result->num_rows;
/*loops through results*/
for ($i=0; $i <$num_results; $i++)
{
$num_found = $i + 1;
$row = $result->fetch_assoc();
echo "<tr class ='text_B'><td>".($row['diamondid'])."</td>";
echo "<td>".($row['shape'])."</td>";
echo "<td><div align='center'>".($row['carat'])."</div></td>";
echo "<td><div align='center'>".($row['color'])."</div></td>";
echo "<td><div align='center'>".($row['clarity'])."</div></td>";
echo "<td>".($row['measurements'])."</span>-<span>".($row['mone'])."</span>x<span>".($row['mtwo'])."</span>mm</td>";
echo "<td><div align='center'>".($row['lab'])."</div></td>";
echo "<td><div align='center'>".($row['priceCT'])."</div></td>";
echo "<td><div align='center'>".($row['price'])."</div></td>";
echo "<td><div align='center'>-".($row['rap'])."</div></td>";
echo "<td><div align='right'><span class='style3'><a href='diamondspec.php?diamondid=".$row['diamondid']."' class='a'>View</a> <br></div></td></tr>";
}
/*free database*/
$dbconn->close();
?>