This topic is locked

How to adjust code

11/20/2008 5:28:36 PM
PHPRunner General questions
V
vytb author

In order to prepopulate a field a from the previous record on the same key Id of table TABLE, I use code
[codebox]

global $conn, $strTableName;

$str = "select TABLE.a

from TABLE where TABLE.Id=".$_SESSION[$strTableName."_masterkey1"];

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

$data = db_fetch_array($rs);
$xt->assign("value_a",$data["a"]);
global $control_a;

$control_a["params"]["value"]=$data["a"];[/codebox]
That's OK.
However, how to adjust this code in order to prepopulate the field from the table that is linked not by primary key of the same table itself but by primary key of a mastertable:
(master) TABLE_A has TABLE left joined on TABLE_A.Id = TABLE.Id

masterkey of TABLE_A is MainId
Thus, I need to prepopulate TABLE.a, from the field a of the previous record in TABLE under the same TABLE_A.MainId.
How to do this?