This topic is locked

readonly field using lookup

2/2/2009 7:49:32 AM
PHPRunner General questions
M
marke author

Hi
I have an edit page with a readonly field that is a foreign key to another table. I would like to be able to use the value in this field to look up the name associated with the record in the foreign key and display the name as the readonly field.
For example I have a table called tblrequirements which contains detail records for a record in tblsimulation. The foreign key in tblrequirements is called simulationID, and this is set to readonly on the Edit Page. I would like the Edit page to display the name of the simulation rather than the id of the simulation record.
I have created a "Before record Updated" event which gets the name from tblsimulation and set this into the relevant value in the $oldvalues array - but it is still displaying the id and not the name.
thanks for your help
Mark

J
Jane 2/2/2009

Mark,
use Add page: Before display event to select and assign value:

global $readonlyfields;

$readonlyfields["FieldName"] = 11111;

M
marke author 2/2/2009

Jane
That's looking promising - but I need to retrieve the required name from another table using the foreign key - which array is this information stored in.
i.e I need to know what I can use for the value to retrieve the information from the other table - should $ABC below be $oldvalues, $values, $data or something else - I'm not sure which array is set with the edit page values at the time this event is triggered

-------- example code -----------------------

global $conn;

global $readonlyfields;
$sql = "SELECT * FROM tblsimulation WHERE idtblsimulation=$ABC['simulationID']";

$result = db_query($sql, $conn);

$row = db_fetch_array($result);
$readonlyfields["simulationID"] = $row["shortname"];
M
marke author 2/3/2009

OK I tried some code I found on another forum response. This is the code I am using in a BeforeShowEdit event on the details table (the master table is tblsimulation - the key to the details table is idtblsimulation in the master table and simulationID in the details table)

global $conn, $readonlyfields;

$i = 1;

$sql = "SELECT * FROM tblsimulation WHERE idtblsimulation=".$_SESSION[$strTablename."_masterkey".$i];

$result = db_query($sql, $conn);

$row = db_fetch_array($result);

$readonlyfields["simulationID"] = $row["shortname"];


This gives an error message when I try to edit the record - undefined variable strTableName

  • there must be a solution to this
    ta
    Mark

J
Jane 2/3/2009

Mark,
just declare $strTableName before:

global $conn, $readonlyfields,$strTableName;

$i = 1;

$sql = "SELECT * FROM tblsimulation WHERE idtblsimulation=".$_SESSION[$strTableName."_masterkey".$i];

$result = db_query($sql, $conn);

$row = db_fetch_array($result);

$readonlyfields["simulationID"] = $row["shortname"];

N
nitinjainDevClub member 2/3/2009

Jane

That's looking promising - but I need to retrieve the required name from another table using the foreign key - which array is this information stored in.
i.e I need to know what I can use for the value to retrieve the information from the other table - should $ABC below be $oldvalues, $values, $data or something else - I'm not sure which array is set with the edit page values at the time this event is triggered

-------- example code -----------------------

global $conn;

global $readonlyfields;
$sql = "SELECT * FROM tblsimulation WHERE idtblsimulation=$ABC['simulationID']";

$result = db_query($sql, $conn);

$row = db_fetch_array($result);
$readonlyfields["simulationID"] = $row["shortname"];


Hi Jane,
Would like to know how to implement the above code.

M
marke author 2/3/2009

Thanks Jane - that works fine now