This topic is locked

Using a session variable with sql query builder

12/30/2009 5:36:27 PM
PHPRunner General questions
L
Lloyd author

Hi,
I am trying to create a report using the sql query builder in phprunner version 5.2b as follows
SELECT

site.name,

url.url name,

url.url type,

url.url address,

access.user id

FROM access

INNER JOIN url ON access.user id = url.id

INNER JOIN site ON url.site id = site.id

WHERE (access.id = $_SESSION[user id])

ORDER BY site.name, url.url name, url.url type, url.url address
The problem is the use of the $_SESSION[user id] in the
WHERE (access.id = $_SESSION[user id]).
Is there a way to select only those recodrs that apply to current user.
Any help in this matter would be greatly appreciated.
Regards,
Lloyd

Sergey Kornilov admin 12/30/2009

It's not possible this way however you can add your own WHERE clause using BeforeSQLQuery event.
See example at http://www.xlinesoft.com/phprunner/docs/modify_sql_query_on_the_fly.htm

L
lewisekrantz 12/30/2009



It's not possible this way however you can add your own WHERE clause using BeforeSQLQuery event.
See example at http://www.xlinesoft.com/phprunner/docs/modify_sql_query_on_the_fly.htm


Look at page 101 of the manual. You also have used incorrect syntax for the SESSION["UserID"]. Look at yours and you will see the difference,

L
Lloyd author 12/30/2009



It's not possible this way however you can add your own WHERE clause using BeforeSQLQuery event.
See example at http://www.xlinesoft.com/phprunner/docs/modify_sql_query_on_the_fly.htm


added the following to the BeforeSQLQuery event:
if ($_SESSION["UserID"]!="admin")

{

$strWhereClause = whereAdd($strWhereClause, "access.id = $_SESSION['user id']");

}
and got a the following error:
syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in line 3
Can you tell me the correct syntax for this.
Thanks
Lloyd

L
lewisekrantz 12/31/2009



added the following to the BeforeSQLQuery event:
if ($_SESSION["UserID"]!="admin")

{

$strWhereClause = whereAdd($strWhereClause, "access.id = $_SESSION['user id']");

}
and got a the following error:
syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in line 3
Can you tell me the correct syntax for this.
Thanks
Lloyd



I think your 'user id' in line three should be "userID" NO SPACES ... your says user id

J
Jane 1/7/2010

LLoyd,
please see my changes below:

if ($_SESSION["UserID"]!="admin")

{

$strWhereClause = whereAdd($strWhereClause, "access.id = '".$_SESSION["UserID"]."'");

}