|
|
|||||||||
|
|||||||||
|
|||||||||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
Free Web 2.0 Code Generator! Generate data entry and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
|
|
#1
|
|||
|
|||
|
PHP Using IF Variables
$a = "1";
$b = "2"; if ($a == $b) { is true } else { is false } The above code works just fine. $filter = "$a == $b"; if ($filter) { is true } else { is false } The above code is always true. I am generating the $filter from user input. I do not know in advance if the operator will be "==" or "!=" . Does anyone know a solution? **** Bowers |
|
#2
|
|||
|
|||
|
Sorry if this is here twice . . . I hit tab-enter and inadvertently submitted. Here's my complete response . . .
Your if statement is checking only that the variable $filter has a value. That's why it's always true. If your user only has two options (== or !=) set each of these possibilities to a value, check for that value, and use a switch. For example: assuming you're getting these values for each possibility, == sets $filter = "equal" != sets $filter = "notEqual" switch ($filter) { case "equal": equal code here . . . $a == $b; break; case "notEqual": not equal code here . . .$a != $b; break; } |
|
#3
|
|||
|
|||
|
I thought that might be the case but i wanted to be sure. It is not the == != that is the problem. There can be up to 20 different combos. I will use SQL to solve the problem.
Thanks for your response. **** Bowers |
![]() |
| Viewing: Dev Articles Community Forums > Programming > PHP Development > PHP Using IF Variables |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|