Jump to content

[SOLVED] Need to add options to If...Else or Use Case Statement.


HowdeeDoodee

Recommended Posts

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.

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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;
}

Link to comment
Share on other sites

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;
}

Link to comment
Share on other sites

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.