kb9yjg Posted May 31, 2008 Share Posted May 31, 2008 The code below is the logic behind an advanced search form with two fields per type i.e. thickness height and date. It seems to be getting stuck around the second case of each switch statement. I need to have either both fields filled in for the between statement, none of them for the like statement or either one or the other for the last two statements... If someone can point out what i did wrong and how to fix it thatd be greatly appreciated. Thanx in advance! if(isset($_GET['thick1']) || isset($_GET['thick2'])){ switch(1) { case ($_GET['thick1']!="" && $_GET['thick2']!=""): $q="select * from $table where pthick between $_GET[thick1] and $_GET[thick2] order by pthick LIMIT $start,$limit"; break; case ($_GET['thick1']=="" && $_GET['thick2']==""): $q="select * from $table where pthick like '%$_GET[thick1]%' order by pthick LIMIT $start,$limit"; break; case ($_GET['thick1']!="" && $_GET['thick2']==""): $q="select * from $table where pthick = $_GET[thick1] order by pthick LIMIT $start,$limit"; break; case ($_GET['thick1']=="" && $_GET['thick2']!=""): $q="select * from $table where pthick = $_GET[thick2] order by pthick LIMIT $start,$limit"; break; } } if(isset($_GET['height1']) || isset($_GET['height2'])){ switch(1) { case ($_GET['height1']!="" && $_GET['height2']!=""): $q="select * from $table where pwidth between $_GET[height1] and $_GET[height2] order by pwidth LIMIT $start,$limit"; break; case ($_GET['height1']=="" && $_GET['height2']==""): $q="select * from $table where pwidth like '%$_GET[height1]%' order by pwidth LIMIT $start,$limit"; break; case ($_GET['height1']!="" && $_GET['height2']==""): $q="select * from $table where pwidth = $_GET[height1] order by pwidth LIMIT $start,$limit"; break; case ($_GET['height1']=="" && $_GET['height2']!=""): $q="select * from $table where pwidth = $_GET[height2] order by pwidth LIMIT $start,$limit"; break; } } if(isset($_GET['date1']) || isset($_GET['date2'])){ switch(1) { case ($_GET['date1']!="" && $_GET['date2']!=""): $q="select * from $table where pdate between $_GET[date1] and $_GET[date2] order by pdate LIMIT $start,$limit"; break; case ($_GET['date1']=="" && $_GET['date2']==""): $q="select * from $table where pdate like '%$_GET[date1]%' order by pdate LIMIT $start,$limit"; break; case ($_GET['date1']!="" && $_GET['date2']==""): $q="select * from $table where pdate = $_GET[date1] order by pdate LIMIT $start,$limit"; break; case ($_GET['date1']=="" && $_GET['date2']!=""): $q="select * from $table where pdate = $_GET[date2] order by pdate LIMIT $start,$limit"; break; } } by the way you can test it out at www.bitsonline.us/don/advsearch.html Link to comment https://forums.phpfreaks.com/topic/108092-weird-glitch-maybe-someone-can-point-out-where-i-went-wrong-and-how-to-fix-it/ Share on other sites More sharing options...
Barand Posted May 31, 2008 Share Posted May 31, 2008 A quick read of your code suggests that no matter what you have in thickness or height fields you will always run a date-based query. Link to comment https://forums.phpfreaks.com/topic/108092-weird-glitch-maybe-someone-can-point-out-where-i-went-wrong-and-how-to-fix-it/#findComment-554079 Share on other sites More sharing options...
kb9yjg Posted May 31, 2008 Author Share Posted May 31, 2008 So now how do you believe it could be fixed to run the correct query/ How would you put together one of those if else switch statements? Link to comment https://forums.phpfreaks.com/topic/108092-weird-glitch-maybe-someone-can-point-out-where-i-went-wrong-and-how-to-fix-it/#findComment-554098 Share on other sites More sharing options...
Barand Posted May 31, 2008 Share Posted May 31, 2008 You don't give any explanation of what is happening, or what isn't happening, so the first thing to do is verify if I have identified the problem correctly. Add some debug code after the code you posted <?php echo '<pre>', print_r($_GET, 1), '<pre>'; // show input echo $q, '<br />'; // show result Link to comment https://forums.phpfreaks.com/topic/108092-weird-glitch-maybe-someone-can-point-out-where-i-went-wrong-and-how-to-fix-it/#findComment-554099 Share on other sites More sharing options...
kb9yjg Posted May 31, 2008 Author Share Posted May 31, 2008 Sorry about that. So first thing that happens is the script checks to see which variables are being used. if(isset($thick1) || isset($thick2)){ If it finds that thick1 and 2 are being used then it starts checking which case is true. I believe it is getting stuck around the second case in each switch. switch(1){ If it finds that the variables and cases arent set or true it goes and checks for the height and so on to the date. Link to comment https://forums.phpfreaks.com/topic/108092-weird-glitch-maybe-someone-can-point-out-where-i-went-wrong-and-how-to-fix-it/#findComment-554347 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.