This topic is locked

Inserting default values from another table on 'Add New'

2/13/2008 11:29:33 AM
PHPRunner General questions
C
comlan author

When a new record is added using "Add New", I need to use some default values from another table for some of the fields.
The field types are Time, Int, and Varchar.
I can see how this could kind of be done using the "Lookup Table", but this does not allow the value to be edited at the time of add or to change these values to something not in the lookup table. Also, there is only one value there to use as the default, so that would not make much sense anyway.
How can this be done?
I am using PHPR 4.2 build 340
Thanks.

J
Jane 2/14/2008

Hi,
you can select required values from another table in the Add page: Before process event on the Events tab and save it in the $_SESSION variables.

Here is a sample:

$str = "select FieldName1,FieldName2 from TableName";

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

$data = db_fetch_array($rs);
$_SESSION["FieldName1"] = $data["FieldName1"];

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



where FieldName1 and FieldName1 are your actual field names, TableName is your actual table name.
Then use these $_SESSION["FieldName1"] and $_SESSION["FieldName1"] as default values on the "Edit as" settings dialog on the Visual Editor tab.

C
comlan author 2/14/2008

Thanks Jane,
Works great.