spangle1187 Posted March 21, 2011 Share Posted March 21, 2011 I have four check boxes that will determine how a search is conducted and I have retrieved the data through _POST[] The problem I have is how can I act upon the data returned? Each of the four text boxes could independently start a search but if I use an If statement the first choice will block the rest of the options eg. if ($clientValue == "on"){ echo "perform a search based on above"; } Quote Link to comment https://forums.phpfreaks.com/topic/231257-if-statement-alternative/ Share on other sites More sharing options...
PFMaBiSmAd Posted March 21, 2011 Share Posted March 21, 2011 To get help with what you are trying to do, you would need to show exactly what you are trying to do and what the expected result should be. Quote Link to comment https://forums.phpfreaks.com/topic/231257-if-statement-alternative/#findComment-1190222 Share on other sites More sharing options...
spangle1187 Posted March 21, 2011 Author Share Posted March 21, 2011 The user fills in a search form containing four input boxes and four check boxes. The four check boxes are used to specify which elements the user wants to use to query the db: 1. client name 2. Room 3. Subject 4. Date The start search button attached to the from calls run_search.php and the information is retrieved using $_POST. Each of the four above can be used as a combination or as an independent search, my first though was to use an if statement based on the check box values: if ($clientValue == "on"){ echo "perform a search based on above"; } but the problem is if the first check box is ticked the the if statement will only run the first part of the statement as the condition has been met. What can I use to search through the results to pick out the combination of the search? I have tried using an array but not sure if this is right? $box=$_POST['box']; while (list ($key,$val) = @each ($box)) { echo "$val,"; } The results will then be passed into an sql query and replace the variable $input and $string to complete the query. $input = "Sam"; $string = "clientName == ".'"'.$input.'"'; $table_id = 'booking'; $query ="SELECT * FROM booking WHERE ". $string; //$test = mysql_query($query); echo $query; I hope this explains my problem a little better, thanks [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/231257-if-statement-alternative/#findComment-1190225 Share on other sites More sharing options...
spangle1187 Posted March 21, 2011 Author Share Posted March 21, 2011 Bump Quote Link to comment https://forums.phpfreaks.com/topic/231257-if-statement-alternative/#findComment-1190374 Share on other sites More sharing options...
Psycho Posted March 21, 2011 Share Posted March 21, 2011 You say you have four text boxes and four checkboxes. Do the checkboxes correspond to the textboxes? If so, why do you need the checkboxes? Just use the fact that a value has been entered into a search field. Anyway, the solution to your problem is fairly simple. Use the input to "build up" the query. Then run the query after you have checked all the user input. Example: $whereClauses = array(); if(isset($_POST['checkbox1'])) { $whereClauses[] = "field1 LIKE '%{$_POST['textbox1']}%'"; } if(isset($_POST['checkbox2'])) { $whereClauses[] = "field2 LIKE '%{$_POST['textbox2']}%'"; } if(isset($_POST['checkbox3'])) { $whereClauses[] = "field3 LIKE '%{$_POST['textbox3']}%'"; } if(isset($_POST['checkbox4'])) { $whereClauses[] = "field4 LIKE '%{$_POST['textbox4']}%'"; } $searchQuery = "SELECT * FROM tableName WHERE " . implode(' AND ', $whereClauses); Quote Link to comment https://forums.phpfreaks.com/topic/231257-if-statement-alternative/#findComment-1190379 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.