This topic is locked
[SOLVED]

 Global Session Variable

2/8/2011 9:18:49 PM
PHPRunner General questions
bbarker author

I am having trouble setting a Session variable.
Ideally, I'd establish this variable when the USER LOGS IN.

I have tableA which only has ONE record with TWO fields; DefaultID and CurrentYear.

I want to read this first (and only record) and then set "CurrentYear" to be $_Session["CurrentYear"]
This is what I've been trying to use:



echo "Following lines in EVENTS Add page: before Process";
global $conn;

$strSQLExists = "select * from tableA where DefaultID='1'";

$rsExists = db_query($strSQLExists,$conn);

$data=db_fetch_array($rsExists);

if($data)

{

$_SESSION["CurrentYear"] = $data["CurrentYear"];

// Show the Session variable

echo "<br/>CurrentYear =";

print_r ($_SESSION["CurrentYear"]);

}



I also unsuccessfully tried:

$_SESSION["CurrentYear"] = $data["tableA_CurrentYear"];
NOTE: Often times I include a table in my databases in which I store "default" information that can be easily changed by the ADMINISTRATOR, and used by any routine that needs these default values. It only contains ONE record. "CurrentYear" is one of the admin-defined values that I change around June and then use it as a default entry value.

Sergey Kornilov admin 2/8/2011

Use AfterSuccessfulLogin event for this purpose. Here is an example:

http://xlinesoft.com/phprunner/docs/save_user_data_in_session_variables.htm

bbarker author 2/9/2011



$_SESSION["FirstName"] = $data["FirstName"];


Thanks Sergey, but I've already tried that.
I think that it needs to define which TABLE the field is in.

So I tried this:

$_SESSION["FirstName"] = $data["TableName_FirstName"];


in accordance with this reference:

http://xlinesoft.com/phprunner/docs/phprunner_session_variables.htm
and that didn't work either.

bbarker author 2/9/2011



This is what the PHPR Manual says:

"...Often you need to save data in session variables for later use. For this purpose you can use AfterSuccessfulLogin event."


But that's not quite what I need ----
How do I save data [color="#FF8C00"]from a different table (not the login table) as a session variable AfterSuccessfulLogin?
LOGIC:

$_SESSION["Field"] = $data["OtherTable_Field"]

bbarker author 2/9/2011

How do I save a table value as a $_SESSION variable from a different table (not the login table) AfterSuccessfulLogin?
I want this to be automatic -- so the user doesn't have to go to any other table/view to make it happen.

Sergey Kornilov admin 2/9/2011

You need to run a SQL query in order to retrieve data from another table. Check sample code in "Data Access Layer" section of the manual for more info.

bbarker author 2/9/2011

I kind of think that that was what I was asking for in my very first posting... oh, well.
SOLUTION:
$sql = "select * from " . 'tablename';

$rs = CustomQuery($sql);

$data = db_fetch_array($rs);

$_SESSION["FIELDNAME"] = $data["FIELDNAME"];
Thanks.