kb9yjg Posted May 29, 2008 Share Posted May 29, 2008 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"; }*/ Link to comment https://forums.phpfreaks.com/topic/107739-determine-which-query-to-run-depending-on-values-recieved-from-an-advanced-searc/ Share on other sites More sharing options...
Gighalen Posted May 29, 2008 Share Posted May 29, 2008 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 } ?> Link to comment https://forums.phpfreaks.com/topic/107739-determine-which-query-to-run-depending-on-values-recieved-from-an-advanced-searc/#findComment-552316 Share on other sites More sharing options...
Gighalen Posted May 29, 2008 Share Posted May 29, 2008 <?php if(empty($_POST['fieldname']){ yada yada yada } ?> should be <?php if(empty($_POST['fieldname'])){ yada yada yada } ?> Link to comment https://forums.phpfreaks.com/topic/107739-determine-which-query-to-run-depending-on-values-recieved-from-an-advanced-searc/#findComment-552317 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.