HowdeeDoodee Posted June 27, 2007 Share Posted June 27, 2007 The first code set below determines the search variable value. The variables are $SeeAlso1, $SeeAlso2, and $SeeAlso3. These variables appear in the search script. Where you see Line 7, 16, 21, I want to add other options so that if a user selects "Use No Wildcard" on the menu page, the script will use $SeeAlso%, or if the user selects "Use Wildcard1" on the search menu page, the script will use $SeeAlso% and if the user selects "Use Wildcard2" the script will use %$SeeAlso%. How do I change the If...Else below into a broader If...Else or use Case statements. Thank you in advance for your replies. if(!empty($TopicFieldSelect)) { $SeeAlso1 = $SeeAlso; //Line 7 } else { $SeeAlso1 = "EditWaldron1"; } if(!empty($SubtopicFieldSelect)) { $SeeAlso2 = $SeeAlso; //line 16 } else { $SeeAlso2 = "EditWaldron2"; } if(!empty($TheswordsFieldSelect)) { $SeeAlso3 = $SeeAlso; //line 21 } else { $SeeAlso3 = "EditWaldron3"; } Here is the query using the variables above... $query2 = "SELECT * FROM `View2_Concord` WHERE (`Source` = $SourceNV OR `Source` = $SourceTR OR `Source` = $SourceBT) AND ($fieldName1 LIKE '$SeeAlso1%' OR $fieldName2 LIKE '$SeeAlso2%' OR $fieldName3 LIKE '$SeeAlso3%') ORDER BY `Lnum` ASC LIMIT $startrecord, $display"; Here is the Select generated from the query SELECT * FROM `View2_Concord` WHERE (`Source` = 'NV' OR `Source` = 'TR' OR `Source` = 'BT') AND (Topic LIKE '%power%' OR Subtopic LIKE '%power%' OR Theswords LIKE '%power%') ORDER BY `Lnum` ASC LIMIT 0, 10 448 is the number of records returned. This query code... $query2 = "SELECT * FROM `View2_Concord` WHERE (`Source` = $SourceNV OR `Source` = $SourceTR OR `Source` = $SourceBT) AND ($fieldName1 LIKE '%$SeeAlso1%' OR $fieldName2 LIKE '%$SeeAlso2%' OR $fieldName3 LIKE '%$SeeAlso3%') ORDER BY `Lnum` ASC LIMIT $startrecord, $display"; Generates this Select... SELECT * FROM `View2_Concord` WHERE (`Source` = 'NV' OR `Source` = 'TR' OR `Source` = 'BT') AND (Topic LIKE 'power%' OR Subtopic LIKE 'power%' OR Theswords LIKE 'power%') ORDER BY `Lnum` ASC LIMIT 0, 10 Retrieves 6 records but the records are more specific than those returned above. Quote Link to comment Share on other sites More sharing options...
corbin Posted June 27, 2007 Share Posted June 27, 2007 if($_POST['check_box_for_wild_card_1']) { $where .= blah; } else { $where .= blah2; } $q = mysql_query("SELECT something FROM somewhere WHERE {$where}"); Quote Link to comment Share on other sites More sharing options...
HowdeeDoodee Posted June 27, 2007 Author Share Posted June 27, 2007 Thank you for the response. I have put together what may be a more understandable explanation of what I need. I have three conditions, conditon 1, condition 2, and condition 3. Maybe a question I should ask is how do I put all of the following if statements under other if statements. Or if I put this line at the top of each of these conditons, what do I put at the bottom or in the middle of the statements? Thank you for any replies. if($_GET['check_box_for_wild_card_1']) { //at the top contion 1 //Condition 1 = Exact match of the search term with no beginning or ending wildcard ($SeeAlso is the search term) if(!empty($TopicFieldSelect)) { $SeeAlso1 = "$SeeAlso"; } else { $SeeAlso1 = "EditWaldron1"; } if(!empty($SubtopicFieldSelect)) { $SeeAlso2 = "$SeeAlso"; } else { $SeeAlso2 = "EditWaldron2"; } if(!empty($TheswordsFieldSelect)) { $SeeAlso3 = "$SeeAlso"; } else { $SeeAlso3 = "EditWaldron3"; } //Condition 2 = Find beginning of search term with wildcard ending ($SeeAlso is the search term) if(!empty($TopicFieldSelect)) { $SeeAlso1 = "$SeeAlso%"; } else { $SeeAlso1 = "EditWaldron1"; } if(!empty($SubtopicFieldSelect)) { $SeeAlso2 = "$SeeAlso%"; } else { $SeeAlso2 = "EditWaldron2"; } if(!empty($TheswordsFieldSelect)) { $SeeAlso3 = "$SeeAlso%"; } else { $SeeAlso3 = "EditWaldron3"; } //Conditon3 = Middle of search term with wildcard beginning and wildcard ending ($SeeAlso is the search term) if(!empty($TopicFieldSelect)) { $SeeAlso1 = "%$SeeAlso%"; } else { $SeeAlso1 = "EditWaldron1"; } if(!empty($SubtopicFieldSelect)) { $SeeAlso2 = "%$SeeAlso%"; } else { $SeeAlso2 = "EditWaldron2"; } if(!empty($TheswordsFieldSelect)) { $SeeAlso3 = "%$SeeAlso%"; } else { $SeeAlso3 = "EditWaldron3"; } Quote Link to comment Share on other sites More sharing options...
HowdeeDoodee Posted June 28, 2007 Author Share Posted June 28, 2007 OK, I am trying to work this out myself. However, I have an error in the following code. The code is to select only one value based upon input. Instead, the code is selecting two values. Can anyone help? Thank you in advance for replies. $WildCardSelect = $_GET[WildCard1]; echo "WildCardSelectNewBranch ========================", $WildCardSelect; if($WildCardSelect = 'WC1') { echo "Hello WorldNewBranch =====================", $WildCardSelect; } elseif($WildCardSelect = 'WC2') { echo "Hello WorldNewBranch =====================", $WildCardSelect; } else if($WildCardSelect = 'WC3') { echo "Hello WorldNewBranch =====================", $WildCardSelect; } Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted June 28, 2007 Share Posted June 28, 2007 you need to use two = signs to determine if it is EQUAL TO. try this code: $WildCardSelect = $_GET[WildCard1]; echo "WildCardSelectNewBranch ========================", $WildCardSelect; if($WildCardSelect == 'WC1') { echo "Hello WorldNewBranch =====================", $WildCardSelect; } elseif($WildCardSelect == 'WC2') { echo "Hello WorldNewBranch =====================", $WildCardSelect; } elseif($WildCardSelect == 'WC3') { echo "Hello WorldNewBranch =====================", $WildCardSelect; } Quote Link to comment 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.