kb9yjg Posted May 29, 2008 Share Posted May 29, 2008 Having trouble trying to get this search script working. I need queries to be run if only one or both fields have been filled. There are multiple fields in the page and each set has a different query to search for profiles on the db. For what ever reason I can not get the switch function nor the if else statements to work properly. I am posting code to both files. If someone can help me I would be extremely grateful. search form <form name="frmAdvSearch" method="get" action="presults.php" onSubmit="return cnvtfrac(this)"> <select id=select1 name=cmbCategory style=HEIGHT: 22px; WIDTH: 153px><option value="" selected><font face=Verdana size=2>All Moldings</font></option><option value="Back_Band">Back Band</option><option value="Base">Base</option><option value="Base_Cap">Base Cap</option><option value="Base_Shoe">Base Shoe</option><option value="Brick_Mold">Brick Mold</option><option value="Casing">Casing</option><option value="Chair_Rail">Chair Rail</option><option value="Corner_Mold">Corner Mold</option><option value="Cornice">Cornice</option><option value="Cove">Cove</option><option value="Crown">Crown</option><option value="Decorative">Decorative</option><option value="Dentil">Dentil</option><option value="Flat_Stock">Flat Stock</option><option value="Half_Round">Half Round</option><option value="Jamb_Stock">Jamb Stock</option><option value="Panel_Mold">Panel Mold</option><option value="Plant_On">Plant On</option><option value="Quarter_Round">Quarter Round</option><option value="Stop">Stop</option><option value="Stucco_Mold">Stucco Mold</option></select><br /><br /> <span class="style10">With a thickness of </span> <input name="thick1" maxlength="10" size="15" style="HEIGHT: 22px; WIDTH: 157px"> <span class="style10">to</span> <input name="thick2" maxlength="10" size="15" style="HEIGHT: 22px; WIDTH: 163px"><br /> <span class="style10">and a Width of </span> <input name="height1" maxlength="10" size="15" style="HEIGHT: 22px; WIDTH: 156px"> <span class="style10">to</span> <input name="height2" maxlength="10" size="15" style="HEIGHT: 22px; WIDTH: 162px"><br /><br /> <span class="style10">and include item numbers that start with</span> <input name="item1" maxlength="15" size="30" style="HEIGHT: 22px; WIDTH: 156px"> <span class="style10">(Blank for all)</span><br /> <span class="style10">and include only items with description containing</span><br /> <input name="descr" maxlength="60" size="80" style="HEIGHT: 22px; WIDTH: 458px" /> <span class="style10">(blank for all)</span><br /> <span class="style10">and show me only items that were added between date (Format: yyyy-mm-dd)</span><br /> <input type="text" name="date1" /> <span class="style10">and date</span> <input type="text" name="date2" value="" /><br /> <input type="submit" name="Submit" value="Submit"> <input type="reset" name="Submit2" value="Reset"> </form> and heres the code for the results page. switch(1) { case ($_GET['thick1']=="" && $_GET['thick2']==""): $q="select * from $table where pthick like $_GET[thick1] and pthick like $_GET[thick2]"; break; case ($_GET['thick1']!="" && $_GET['thick2']!=""): $q="select * from $table where pthick between $_GET[thick1] and $_GET[thick2]"; break; case ($_GET['thick1']!="" && $_GET['thick2']==""): $q="select * from $table where pthick = $_GET[thick1]"; break; case ($_GET['thick1']=="" && $_GET['thick2']!=""): $q="select * from $table where pthick = $_GET[thick2]"; break; case ($_GET['height1']=="" && $_GET['height2']==""): $q="select * from $table where pwidth like $_GET[height1] and pwidth like $_GET[height2]"; break; case ($_GET['height1']!="" && $_GET['height2']!=""): $q="select * from $table where pwidth between $_GET[height1] and $_GET[height2]"; break; case ($_GET['height1']!="" && $_GET['height2']==""): $q="select * from $table where pwidth = $_GET[height1]"; break; case ($_GET['height1']=="" && $_GET['height2']!=""): $q="select * from $table where pwidth = $_GET[height2]"; break; case ($_GET['item1']==""): $q="select * from $table where itemno != $_GET[item1]"; break; case ($_GET['item1']!=""): $q="select * from $table where itemno like $_GET[item1]"; break; case ($_GET['descr']==""): $q="select * from $table where itemno != $_GET[descr]"; break; case ($_GET['descr']!=""): $q="select * from $table where itemno like $_GET[descr]"; break; case ($_GET['date1']=="" && $_GET['date2']==""): $q="select * from $table where pdate like $_GET[date1] and pdate like $_GET[date2]"; break; case ($_GET['date1']!="" && $_GET['date2']!=""): $q="select * from $table where pdate between $_GET[date1] and $_GET[date2]"; break; case ($_GET['date1']!="" && $_GET['date2']==""): $q="select * from $table where pdate = $_GET[date1]"; break; case ($_GET['date1']=="" && $_GET['date2']!=""): $q="select * from $table where pdate = $_GET[date2]"; break; } /* if (isset($_GET['thick1']) && isset($_GET['thick2'])){ $q="select * from profiles where pthick between '$thick1' and '$thick2' order by pid LIMIT $start,$limit"; } if (!empty($height1) && !empty($height2)){ $q="select * from profiles where pwidth between '$height1' and '$height2' or pwidth = '$height1' or pwidth = '$height2' order by pid LIMIT $start,$limit"; } if(isset($descr)){ $q="select * from profiles where pdesc like '%$descr%' order by pid LIMIT $start,$limit"; } if(isset($item1)){ $q="select * from profiles where itemno like '%$item1%' order by pid LIMIT $start,$limit"; } if(isset($date1) && isset($date2)){ $q="select * from profiles where pdate between '$date1' and '$date2' or pdate = '$date1' or pdate = '$date2' order by pid LIMIT $start,$limit"; }*/ if(isset($cmbCategory)){ $q="select * from profiles where ptype like '%$cmbCategory%' order by pid LIMIT $start,$limit"; }elseif(isset($cmbNewCategory) || isset($_GET['GO'])){ $q="select * from profiles where ptype like '%$cmbNewCategory%' order by pid LIMIT $start,$limit"; } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.