Hi,
I am not a php programmer, but I’ve been trying to learn through tutorials. I am still very new to it. I am trying to create an advanced search for a site that has checkboxes, droplists, and search by range. I have gotten to the point where I can search by one value of each field of my table. How can I do a multiple search for each field( i.e. search by 4 diff values of the same field )
my form is:
<form action="template_search.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="searchshapetwo" 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>
and the results page is:
[code]<?php
/*set varibles from form */
$searchshape = addslashes($_POST[‘searchshape’]);
$searchshapetwo = addslashes($_POST[‘searchshapetwo’]);
$searchlab = addslashes($_POST[‘searchlab’]);
$searchshape = trim ($searchshape);
$searchshapetwo = trim ($searchshapetwo);
$searchlab = trim ($searchlab);
/check if search term was entered/
/add slashes to search term/
if (!get_magic_quotes_gpc())
{
$searchshape = addslashes($searchshape);
$searchshapetwo = addslashes($searchshapetwo);
$searchlab = addslashes($searchlab);
}
/* 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 "
ID# | "; echo "Shape | "; echo "Carat | "; echo "Color | "; echo "Clarity | "; echo "Measurements | ";
echo "Lab | ";
echo "Price/ct | "; echo "Price | "; echo "%Rap | "; echo "Details |
”.($row[‘diamondid’])." | ";”.($row[‘shape’])." | ";”.($row[‘carat’])." | ";”.($row[‘color’])." | ";”.($row[‘clarity’])." | ";”.($row[‘measurements’])."-".($row[‘mone’]).“x”.($row[‘mtwo’]).“mm | ”;”.($row[‘lab’])." | ";”.($row[‘priceCT’])." | ";”.($row[‘price’])." | ";-”.($row[‘rap’])." | ";<a href='diamondspec.php?diamondid=”.$row[‘diamondid’]."’ class=‘a’>View |