Jump to content

Recommended Posts

Hello I have been working on an advanced search script. I have two bits of code which I will post. I need one or the other to work. I need it to where thick1 and thick2 can be both filled in or left blank or one or the other filled in. The same goes for height1, height2 and date1 and date2. If someone can show me an easier way to get this all completed and working great that would be appreciated.

 

switch code (pardon comments trying to work through to get it solved.)

switch(1)
{
case (empty($_GET['thick1']) && empty($_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;
}

 

and heres the if else statements

if (isset($thick1) && isset($thick2)){
$q="select * from profiles where pthick between $_GET[thick1] and $_GET[thick2] order by pid LIMIT $start,$limit";
}
if (isset($height1) && isset($height2)){
$q="select * from profiles where pwidth between $_GET[height1] and $_GET[height2] order by pid LIMIT $start,$limit";
}
	if(isset($descr)){
	$q="select * from profiles where pdesc like '%$_GET[descr]%' order by pid LIMIT $start,$limit";
	}
		if(isset($item1)){
		$q="select * from profiles where itemno like '%$_GET[item1]%' order by pid LIMIT $start,$limit";
		}
			if(isset($date1) && isset($date2)){
			$q="select * from profiles where pdate between '$_GET[date1]' and '$_GET[date2]' order by pid LIMIT $start,$limit";
			}
				if(isset($cmbCategory)){
				$q="select * from profiles where ptype like '%$_GET[cmbCategory]%' order by pid LIMIT $start,$limit";
				}
				if(isset($cmbNewCategory)){
					$q="select * from profiles where ptype like '%$_GET[cmbNewCategory]%' order by pid LIMIT $start,$limit";
					}

Your help is greatly needed and appreciated. I Thank you in advance.

 

When I make a search engine type form, instead of making a query for every single possible combo, I try to set up the form so that I can I build the query string up piece by piece.  The key is to look at all of your combos and find the common denominators and reduce, just like you learned in 2nd grade math, only you're using words instead of numbers.

 

 

 

 

Hey everyone thanks for the help... Posting the code for anyone that may run into this issue in the future...

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 (empty($_GET['thick1']) && empty($_GET['thick2'])):
$q="select * from $table where pthick like '%$_GET[thick1]%' order by pthick LIMIT $start,$limit";
break;
case ($_GET['thick1']!="" && empty($_GET['thick2'])):
$q="select * from $table where pthick = $_GET[thick1] order by pthick LIMIT $start,$limit";
break;
case (empty($_GET['thick1']) && $_GET['thick2']!=""):
$q="select * from $table where pthick = $_GET[thick2] order by pthick LIMIT $start,$limit";
break;
case ($_GET['item1']==""):
$q="select * from $table where itemno like %$_GET[item1]% order by itemno LIMIT $start,$limit";
break;
case ($_GET['item1']!=""):
$q="select * from $table where itemno like %$_GET[item1]% order by itemno LIMIT $start,$limit";
break;
case ($_GET['descr']==""):
$q="select * from $table where pdesc like %$_GET[descr]% order by pdesc LIMIT $start,$limit";
break;
case ($_GET['descr']!=""):
$q="select * from $table where pdesc like %$_GET[descr]% order by pdesc 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 (empty($_GET['height1']) && empty($_GET['height2'])):
$q="select * from $table where pwidth like '%$_GET[height1]%' order by pwidth LIMIT $start,$limit";
break;
case ($_GET['height1']!="" && empty($_GET['height2'])):
$q="select * from $table where pwidth = $_GET[height1] order by pwidth LIMIT $start,$limit";
break;
case (empty($_GET['height1']) && $_GET['height2']!=""):
$q="select * from $table where pwidth = $_GET[height2] order by pwidth LIMIT $start,$limit";
break;
case ($_GET['item1']==""):
$q="select * from $table where itemno like %$_GET[item1]% order by itemno LIMIT $start,$limit";
break;
case ($_GET['item1']!=""):
$q="select * from $table where itemno like %$_GET[item1]% order by itemno LIMIT $start,$limit";
break;
case ($_GET['descr']==""):
$q="select * from $table where pdesc like %$_GET[descr]% order by pdesc LIMIT $start,$limit";
break;
case ($_GET['descr']!=""):
$q="select * from $table where pdesc like %$_GET[descr]% order by pdesc 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 (empty($_GET['date1']) && empty($_GET['date2'])):
$q="select * from $table where pdate like '%$_GET[date1]%' order by pdate LIMIT $start,$limit";
break;
case ($_GET['date1']!="" && empty($_GET['date2'])):
$q="select * from $table where pdate = $_GET[date1] order by pdate LIMIT $start,$limit";
break;
case (empty($_GET['date1']) && $_GET['date2']!=""):
$q="select * from $table where pdate = $_GET[date2] order by pdate LIMIT $start,$limit";
break;
case ($_GET['item1']==""):
$q="select * from $table where itemno like %$_GET[item1]% order by itemno LIMIT $start,$limit";
break;
case ($_GET['item1']!=""):
$q="select * from $table where itemno like %$_GET[item1]% order by itemno LIMIT $start,$limit";
break;
case ($_GET['descr']==""):
$q="select * from $table where pdesc like %$_GET[descr]% order by pdesc LIMIT $start,$limit";
break;
case ($_GET['descr']!=""):
$q="select * from $table where pdesc like %$_GET[descr]% order by pdesc LIMIT $start,$limit";
break;
}
}

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.