This topic is locked

What gets passed from master to slave tables?

9/10/2008 7:42:01 AM
PHPRunner General questions
T
thesofa author

When I click the link next to a record on a master table, what gets passed to the slave table list page?

Can I access it?

whan I click "Inline Add", what if anything from the master table is availble for me to use?

J
Jane 9/11/2008

Hi,
you can use following session variables on the list, add and edit pages of detail table:

$_SESSION[$strTableName."_mastertable"] - Master table name

$_SESSION[$strTableName."_masterkey1"] - Master table foreign key value

T
thesofa author 9/11/2008

Hi,

you can use following session variables on the list, add and edit pages of detail table:

$_SESSION[$strTableName."_mastertable"] - Master table name

$_SESSION[$strTableName."_masterkey1"] - Master table foreign key value



so if i want to use some values from the master page, how do I access the details from the row before I click the Inline Add button, then I can get them into session variables and use them as default values for the new record!

J
Jane 9/11/2008

Hi,
just select required values in the List page: Before process event for detail table.

Here is a sample:

global $conn, $strTableName;

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

{

$str = "select Field1,Field2 from MasterTable where Key=".$_SESSION[$strTableName."_masterkey1"];

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

$data = db_fetch_array($rs);

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

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

}

T
thesofa author 9/11/2008

Hi,

just select required values in the List page: Before process event for detail table.

Here is a sample:



Hi Jane, you make me feel so dim at times, I have tried this and none of the session variables get populated.

global $conn, $strTableName;

echo $_SESSION[$strTableName."_masterkey1"];

echo $_SESSION[$strTableName."_mastertable"];

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

{

$str = "select nd_details.day4det,nd_dept_list.department,nd_details.id_det from DetMissed where Key=".$_SESSION[$strTableName."_masterkey1"];

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

$data = db_fetch_array($rs);

$_SESSION["d4d"] = $data["nd_details.day4det"];

$_SESSION["dept"] = $data["nd_dept_list.department"];

$_SESSION["id"] = $data["nd_details.id_det"];

}

echo $str;
//nd_details.id_det

//nd_details.day4det

//nd_dept_list.department


like this it trips up with an error on the

echo $str;



line so I commented it out and none of the session variable have anything in

Shall I do a better description of what I am doing?

J
Jane 9/12/2008

Hi,
first I don't understand your SQL query.

You have added table prefix and selected fields from another table.

Also your $str is not defined outside IF construction.

I've made some corrections in your code:

global $conn, $strTableName;

echo $_SESSION[$strTableName."_masterkey1"];

echo $_SESSION[$strTableName."_mastertable"];

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

{

$str = "select day4det,department,id_det from DetMissed where Key=".$_SESSION[$strTableName."_masterkey1"];

echo $str;

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

$data = db_fetch_array($rs);

$_SESSION["d4d"] = $data["day4det"];

$_SESSION["dept"] = $data["department"];

$_SESSION["id"] = $data["id_det"];



echo "day4det: ".$_SESSION["d4d"];

echo "department: ".$_SESSION["dept"];

echo "id_det: ".$_SESSION["id"];


}

U
Urnso 9/12/2008

[codebox]global $conn, $strTableName;

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

{

$str = "select Field1,Field2 from MasterTable where Key=".$_SESSION[$strTableName."_masterkey1"];

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

$data = db_fetch_array($rs);

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

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

}[/codebox]
Jane,
I am using this code now and it is working for me. The problem is after I click add I have to refresh the page to get the fields to populate.

IE6 and Firefox 3 same results.
Once the record is added the session data remains until the browser is closed.
If the user selects back to list can you unset() those variables so they are not being passed the next time they click add?
I guess you would also need to unset() them after you add the record correct?
Would you just unset($_SESSION["Field1"]; in the after record added event area? The back to list button has me stumped.
Thx!

J
Jane 9/15/2008

Hi,
to unset these variables just add following code in the After record added event:

$_SESSION["Field1"] = "";


Also you can assign values directly in the Before display event:

$smarty->assign("value_FieldName1",$data["Field1"]);

$smarty->assign("value_FieldName2",$data["Field2"]);