Jump to content

determine which query to run depending on values recieved from an advanced searc


kb9yjg

Recommended Posts

Hello all, I have a db that will be full of 3k + entries. I have a form that has several areas that can be filled in. What I want is to run a different query depending on which field or box will be filled in or left blank.  For instance if one or the other fields for thickness are filled/empty then the query for thickness runs. If one or the other fields for height are filled/empty then the query for height runs and the same for date fields. Below is my code. Your help would be greatly appreciated. I have the other if statements commented out so I can focus in on one at a time.

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";
					}*/

 

 

If you want to run a query if they filled out a field (assuming your using the POST method):

 

<?php
if(isset($_POST['fieldname'])){
yada yada yada
}
?>

Or if they DIDNT fill out a field:

<?php
if(empty($_POST['fieldname']){
yada yada yada
}
?>

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.