This topic is locked

clearing the session values

10/31/2011 11:23:06 AM
PHPRunner General questions
V
vytb author

Hello,
I have events prepopulating the values from the last observation of the same subject.
For ex., a default value for a variable is $_SESSION["UGI"]

For an add event I put

global $conn, $strTableName;

if ($_SESSION[$strTableName."_masterkey1"])

{
$str = "select SubjectId, id

from visit where id=".$_SESSION[$strTableName."_masterkey1"];

$rs = db_query($str,$conn);

if ($data = db_fetch_array($rs))

{
$str = "select visit.SubjectId, visit.id, VisitNb from visit

inner join loc on visit.id=loc.visitid

where SubjectId=".$data["SubjectId"]." Order by VisitNb desc";

$rs = db_query($str,$conn);

if($data2 = db_fetch_array($rs))

{
$str = "select UGI

from loc where visitid=".$data2["id"];

$rs = db_query($str,$conn);

$data1 = db_fetch_array($rs);
$_SESSION["UGI"] =$data1["UGI"];
}

}

}


Everything works OK. However these default values appear for the new subjects as well if I add a new one. How to avoid this?

C
cgphp 10/31/2011

Not sure I understand what you mean. To unset a session var:

unset($_SESSION['UGI']);


Please, try to explain the workflow of how you use the session var.

V
vytb author 10/31/2011



Not sure I understand what you mean. To unset a session var:

unset($_SESSION['UGI']);


Please, try to explain the workflow of how you use the session var.


OK. I have a number of subjects that have recurrent visits. Every visit takes a number of pages. Some variables of these pages of the visits have the same values for the particular subject. Thus I pre-populate these variables using the code I've mentioned above. However if it happens to add an additional subject, related variables from earlier visit of another subject may be left.
If unset() is to use, should I include this function for every session variable event for every page before setting it, or there is a more elegant possibility?

C
cgphp 10/31/2011

Not sure I understand the logic behind your app. If you want to execute some code in the beginning of each page before any processing takes place, check this event: http://xlinesoft.com/phprunner/docs/after_table_initialized.htm