HowdeeDoodee
Technical User
I need to append my SELECT statement with checkbox value combinations. The user can select one or all of the six checkboxes. The checkbox values do not appear in the db at the same time so I would want the SELECT statement to pull up different values separated by the OR operator not the AND operator. Checkbox values separated by an AND operator would find no records. The checkbox values would be associated with the Source field in the db.
The checkbox values coming in from the form are ES, TH, SM, NV, TR, and EN. In the code below, The value from the form is made equal to a variable, the variable is put in a string with the word Source. That string is then made equal to another variable.
My question is...how do I code the query statement so any of the checkbox variables are searched? What you see below needs correction.
Edited to add: One of the problems with the code below is that I do not know how to handle a variable if there are no values in the variable. If the user selects two checkboxes, the query statement at the bottom the this code has six variables in it. In this example, four of those variables would be empty. Don't I need a way to avoid empty variables? Thank you in advance for any replies.
$TH1 = "`Source`={$TH}";
}
if(!empty($SM)){
$SM = "'SM'";
$SM1 = "`Source`={$SM}";
}
if(!empty($NV)){
$NV = "'NV'";
$NV1 = "`Source`={$NV}";
}
if(!empty($TR)){
$TR = "'TR'";
$TR1 = "`Source`={$TR}";
}
if(!empty($EN)){
$EN = "'EN'";
$EN1 = "`Source`={$EN}";
}
//the following code needs correction
$query = $query . AND . ($ES1 OR $TH1 OR $SM1 OR $NV1 OR $TR1 OR $EN1);
The checkbox values coming in from the form are ES, TH, SM, NV, TR, and EN. In the code below, The value from the form is made equal to a variable, the variable is put in a string with the word Source. That string is then made equal to another variable.
My question is...how do I code the query statement so any of the checkbox variables are searched? What you see below needs correction.
Edited to add: One of the problems with the code below is that I do not know how to handle a variable if there are no values in the variable. If the user selects two checkboxes, the query statement at the bottom the this code has six variables in it. In this example, four of those variables would be empty. Don't I need a way to avoid empty variables? Thank you in advance for any replies.
Code:
$query = "SELECT * FROM `View2` WHERE `Topic` REGEXP '[[:<:]]($SeeAlso)[[:>:]]'";
if(!empty($ES)){
$ES = "'ES'";
$ES1 = "`Source`={$ES}";
}
if(!empty($TH)){
$TH = "'TH'";
}
if(!empty($SM)){
$SM = "'SM'";
$SM1 = "`Source`={$SM}";
}
if(!empty($NV)){
$NV = "'NV'";
$NV1 = "`Source`={$NV}";
}
if(!empty($TR)){
$TR = "'TR'";
$TR1 = "`Source`={$TR}";
}
if(!empty($EN)){
$EN = "'EN'";
$EN1 = "`Source`={$EN}";
}
//the following code needs correction
$query = $query . AND . ($ES1 OR $TH1 OR $SM1 OR $NV1 OR $TR1 OR $EN1);