This topic is locked

session Variables in SQL Query

8/20/2008 12:36:15 PM
PHPRunner General questions
K
kenny_robb author

Is it possible to pass a session variable that has been set at logon time into a query in order to pull out a subset of data.
For example if I set $_SESSION["country"] = "UK" in the login event
can I then user $_SESSION["country"] in a SQL query for one of my tables in the Edit SQl Query tab
for example

select

a,

b,

c,

d

from main_table

where a= $_SESSION["country"]
thanks in anticipation
kenny

A
alang 8/20/2008

What about using a fixed "placeholder" in the SQL on the "Edit SQL query" tab then add some code in the Before SQL query to substitute the placeholder with your $_SESSION variable value?

K
kenny_robb author 8/21/2008

What about using a fixed "placeholder" in the SQL on the "Edit SQL query" tab then add some code in the Before SQL query to substitute the placeholder with your $_SESSION variable value?


That sounds like a possibility....what is the format of the fixed placeholder in the EDIT SQL?

J
Jane 8/21/2008

Hi,
just use Before SQL query event to add where clause to your SQL query.

Here is a sample:

if ($_SESSION["country"])

$strWhereClause = whereAdd($strWhereClause,"a=".$_SESSION["country"]);

K
kenny_robb author 8/21/2008

Hi,

just use Before SQL query event to add where clause to your SQL query.

Here is a sample:


Thanks Jane thats worked fantastically...
Kenny