This topic is locked

Lookup wizard WHERE condition

12/18/2017 4:25:23 PM
PHPRunner General questions
W
wpl author

Dear Runners,
up to PHPRunner 9.7, the posibility existed to build a WHERE condition in Lookup wizard with a PHP-Expression:
"Description

You should enter a valid PHP expression here which will be added to SQL string.

Don't forget to quote the strings."
So one could check for the existence of a $_SESSION-variable build a WHERE clause with it or leave the clause empty

if the $_SESSION-variable does not exist or is empty, which was quite convenient.
Starting with PHPRunner 9.8, the lookup wizard says:
"Description

Enter valid WHERE-expression here, which will be added to SQL string.

Also you can use substitutions to be replaced when the query is executed"
So checking for the existence of a variable like so:
if(isset($_SESSION["somevar"]) && !empty($_SESSION["somevar"]))
will result in a syntax error. Thus, one can still use $_SESSION-vars, but they cannot be checked via PHP beforehand.
Any one with an idea to solve this?
Season's Greetings and TIA

romaldus 12/18/2017

You cannot use php "IF" statement in phprunner lookup WHERE. To solve this, create a new session in "before display event" to check some vars existence and than use that session in lookup WHERE.

W
wpl author 12/19/2017



You cannot use php "IF" statement in phprunner lookup WHERE. To solve this, create a new session in "before display event" to check some vars existence and than use that session in lookup WHERE.



romaldus,
thanks for joining. I was afraid that this would be the way to go. As said earlier, until PHPRunner 9.7 you could write
(isset($_SESSION["someVar"]) && !empty($_SESSION["someVar"]) ? "lookuptable.someField=" . $_SESSION["someVar"] : "")
in the WHERE section of a lookup wizard. This would build a WHERE condition if the variable was set and an empty string if not.

So now it seems you would have to put this in a new $_SESSION var for the different lookup fields on a page for use in the respective lookup wizard.
Thanks and regards

Admin 12/22/2017

This wasn't a correct syntax before and is not now. But, you can use ternary operator in PHP to achieve this:

https://www.abeautifulsite.net/how-to-use-the-php-ternary-operator

W
wpl author 12/22/2017



This wasn't a correct syntax before and is not now. But, you can use ternary operator in PHP to achieve this:

https://www.abeautifulsite.net/how-to-use-the-php-ternary-operator


Maybe incorrect but working.

Admin 12/22/2017

Some people just have to have the last word. You won.