Jump to content

weird glitch. maybe someone can point out where i went wrong and how to fix it?


kb9yjg

Recommended Posts

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

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

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.