Jump to content

[SOLVED] IF...ElSE using radio button input not working


HowdeeDoodee

Recommended Posts

I have a form with radio button values being sent to the script. The value of the variable $Boolselect in the code below is supposed to determine which part of the query IF Else is executed. If the script runs like I want the script to run and if the value of $Boolselect = "" then only the last part of the query IF ELSE is to run. The problem with this code is the last part of the query IF ELSE is executed whether $Boolselect is full or empty. Can someone give me suggestions as to how to change the code so only the last part of the query IF ELSE runs when $bool is empty? Thank you in advance for any replies.

 

The value for $Boolselect is derived from the Rad1Select If Else shown below. $Rad1Select refers to radio button select.

 

<?

//the radio button creating the "ON4" condition is selected or not selected and values are sent to this part of the script

if ($Rad1Select == "ON1")
  $AllWords = "'All Words'" AND $Rad1Select = "''";
   else
   {
   $AllWords = "''";
   }

if ($Rad1Select == "ON2")
  $AnyWords = "'Any Words'" AND $Rad1Select = "''";
   else
   {
   $AnyWords = "''";
   }


if ($Rad1Select == "ON3")
  $ExactPhr = "'Exact Phrase'" AND $Rad1Select = "''";
   else
   {
   $ExactPhr = "''";
   }

if ($Rad1Select == "ON4")
  $Boolselect = "'Boolean'" AND $Rad1Select = "''";
   else
   {
   $Boolselect = "''";
   }


//the query IF ELSE starts here

if (($boolean == TRUE) && ($split == "OR") && ($Boolselect == "Boolean")) {
$query2 = "SELECT * FROM `View2_ConcordFT` WHERE MATCH($fieldName1, $fieldName2, $fieldName3) AGAINST ('$terms[0] $terms[1] $terms[2] $terms[3] $terms[4] $terms[5]' IN BOOLEAN MODE) ORDER BY `Lnum` ASC LIMIT $startrecord, $display";
echo "string boolean===========", $Boolselect;
echo "query2 boolean OR===========", $query2;

} 

elseif (($boolean == TRUE) && ($split == "AND") && ($Boolselect == "Boolean")) 

{ 
$query2 = "SELECT * FROM `View2_ConcordFT` WHERE MATCH($fieldName1, $fieldName2, $fieldName3) AGAINST ('+$terms[0] +$terms[1] +$terms[2] +$terms[3] +$terms[4] +$terms[5]' IN BOOLEAN MODE) ORDER BY `Lnum` ASC LIMIT $startrecord, $display"; 
echo "string boolean===========", $Boolselect;
echo "query2 AND===========", $query2;

} else { 


$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";
echo "string boolean===========", $Boolselect;
echo "query2 non boolean===========", $query2;
}


?>

 

Here is the output after the script is run.

 

//string $Boolselect==========='Boolean'

//query2 non boolean===========SELECT * FROM

`View2_Concord` WHERE (`Source` = 'NV' OR `Source` = 'TR' OR `Source` = 'BT') AND (Topic LIKE '%adam and edward%' OR Subtopic LIKE '%adam and edward%' OR Theswords LIKE '%adam and edward%') ORDER BY `Lnum` ASC LIMIT 0, 10

 

 

Thank you for the response.

 

$boolean is being set at the top of the script. The part of the code that determines $boolean takes the input from the form's input box and tests the input for the word's AND or OR. Thank you again for the response.

 

Here is the code that determines the value of $boolean

 

 

if ($trimmed == "" | !isset($var))
  {
  echo "<h" . $hlevel . ">Error! No valid search term was entered.</h" . $hlevel . ">";
  $skip = TRUE;
  }

if (ereg(" AND | and | And | aND | AnD | anD ",$trimmed,$matches)) {
$burst = $matches[0];
$terms = explode($burst,$trimmed);
$boolean = TRUE;
$split = "AND"; 
} elseif (ereg(" OR | or | Or | oR ",$trimmed, $matches)) {
$burst = $matches[0];
$terms = explode($burst,$trimmed);
$boolean = TRUE;
$split = "OR"; 
} 
  if (empty($s)) {
  $s=0;
  }
  { 
  }

Changing Line 1 to Line 2 solves one problem, that being making the first and second query elseif work as they should. However, changing these lines creates another problem in that the third query elseif does not execute because the $Boolselect has been removed. How do I make the third query statement execute when only an empty value of $Boolselect is present?

 

Line 1

elseif (($boolean == TRUE) && ($split == "AND") && ($Boolselect == 'Boolean')) 


Line 2

elseif (($boolean == TRUE) && ($split == "AND")) 

 

 

What is even more baffling is that the following code works as expected. Commenting out the $split values demonstrates the code.

 

<?

//the radio button creating the "ON4" condition is selected or not selected and values are sent to this part of the script

if ($Rad1Select == "ON1")
  $AllWords = "'All Words'" AND $Rad1Select = "''";
   else
   {
   $AllWords = "''";
   }

if ($Rad1Select == "ON2")
  $AnyWords = "'Any Words'" AND $Rad1Select = "''";
   else
   {
   $AnyWords = "''";
   }


if ($Rad1Select == "ON3")
  $ExactPhr = "'Exact Phrase'" AND $Rad1Select = "''";
   else
   {
   $ExactPhr = "''";
   }

if ($Rad1Select == "ON4")
  $Boolselect = "'Boolean'" AND $Rad1Select = "''";
   else
   {
   $Boolselect = "''";
   }

$boolean = TRUE;
//$split = "AND";
//$split = "OR";
$Bool = "Boolean";

echo "BoolselectTOP==============", $Boolselect;
echo "<p>\n";
echo "</p>\n";
echo "booleanTOP=================", $boolean;
echo "<p>\n";
echo "</p>\n";
echo "splitTOP===================", $split;
echo "<p>\n";
echo "</p>\n";

//the query IF ELSE starts here



if (($boolean == TRUE) && ($split == "OR") && ($Boolselect == "Boolean")) {

echo "Boolselect==============", $Bool;
echo "<p>\n";
echo "</p>\n";
echo "boolean=================", $boolean;
echo "<p>\n";
echo "</p>\n";
echo "split===================", $split;
echo "<p>\n";
echo "</p>\n";
echo "query2 boolean OR===========", $query2;
echo "<p>\n";
echo "</p>\n";
} 

elseif (($boolean == TRUE) && ($split == "AND") && ($Boolselect == "Boolean")) 

{ 
echo "Boolselect==============", $Bool;
echo "<p>\n";
echo "</p>\n";
echo "boolean=================", $boolean;
echo "<p>\n";
echo "</p>\n";
echo "split===================", $split;
echo "<p>\n";
echo "</p>\n";
echo "query2 AND===========", $query2;
echo "<p>\n";
echo "</p>\n";
} else { 

echo "Boolselect==============", $Bool;
echo "<p>\n";
echo "</p>\n";
echo "boolean=================", $boolean;
echo "<p>\n";
echo "</p>\n";
echo "split===================", $split;
echo "<p>\n";
echo "</p>\n";
echo "query2 non boolean===========", $query2;

}

?>

 

 

 

This topic has been solved by making the $boolean variable conditional upon the values passed to $Rad1Select

 

$Rad1Select = $_GET['Rad1'];

if($Rad1Select == 'ON1'){
  $boolean = False;
   }
   else
   {
  $boolean = "";
   }

if($Rad1Select == 'ON2'){
  $boolean = False;
   }
   else
   {
  $boolean = "";
   }

if($Rad1Select == 'ON3'){
  $boolean = False;
   }
   else
   {
  $boolean = "";
   }

if($Rad1Select == 'ON4'){
  $boolean = True;
   }
   else
   {
  $boolean = "";
   }

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.