This topic is locked

Populating fields from another table

10/25/2007 10:43:11 AM
PHPRunner General questions
L
Lisa2006 author

Hi All,
Table: _drivers

Field: company
Table: journey

Field: companyname
While i'm adding a new record via the journey table, i want to be able to extract the contents of the company field (Table _drivers) and populate this into the field companyname (Table journey).
Please Help
Lisa

J
jskewes 10/25/2007

Hi Lisa - I think you are looking for the Lookup Wizard function.

In the visual editor --> choose the Add Page --> select the field you want (double click) --> in Edit As --> choose Lookup Wizard.

The rest should come pretty easy - if this is what you are looking for.

/john

Hi All,

Table: _drivers

Field: company
Table: journey

Field: companyname
While i'm adding a new record via the journey table, i want to be able to extract the contents of the company field (Table _drivers) and populate this into the field companyname (Table journey).
Please Help
Lisa

H
horsey_kim 10/25/2007

Oh I think I can help you on this one <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=22592&image=1&table=forumreplies' class='bbc_emoticon' alt=':)' />
In the visual editor, double click the yellow field. Up pops a menu, Select Edit As Tab
Then Select the Lookup Wizard.
Click the Lookup table bullet
Then under the table pull down menu select your _driver table
Next in the pull downs for Link field and Display field select your field company. You can also select the order by to sort by company field so they are in alphabetic order. I usually click the unique value box too, just so I only see one of each items.
I believe with the visual editor you only have to do it once to that field and it should be the say for the list, edit, or add page for that table view. Now if you create other tables, you have to do it for that too.
I hope that helps and that is what you were after.
Have a great day,
Kim

H
horsey_kim 10/25/2007

Oh John beat me! I am just too long winded.
Kim

L
Lisa2006 author 10/25/2007

Hi All,
Thanks for your reply.
Unfortunately, this does not solve the problem. Using the proposed method, it simply presents a drop down box where the user would have to select from a list.
I'm trying to do the following.
1] On the Add Page (journey table) the field companyname will not be readonly

At this point i want the company field from the _drivers table to populate the companyname field in the journey table.

2] User will then enter other field information.

3] User then clicks Save
Hope someone can help.
Lisa

H
horsey_kim 10/25/2007

Might need a little more info. How is the field to know which company to fill in Is there some other variable in your Journy table that will allow the system to know what company to populate?
Kim

L
Lisa2006 author 10/26/2007

Hi All,
I have setup the journey table as follows:
Advanced security settings | Users can see and edit their own data only

Users Table: OwnerID field = ID (this is from _drivers table)

Main Table: OwnerID field = courierid (this is from journey table)
When i build the project & Login, i have access to both _driver table & journey table.
Note: at this point the _driver table is populated with user information.
I simply click on the journey table, click Add new in order to create a new record with journey related information. Upon completion the journey table courierid field is populated with the ID value from the _drivers table. At this point i want to extract the _drivers company field information into journey companyname field.
Hope someone can help

J
Jane 10/26/2007

Hi,
try to use following code:

global $conn;

$str = "select company from _drivers where username='".$_SESSION["UserID"]."'";

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

if($data = db_fetch_array($rs))

$values["companyname"] = $data["company"];

L
Lisa2006 author 10/26/2007

Sorry, still not working.
Can you advise what Add event and event type the code should be placed into
Lisa

J
Jane 10/26/2007

answered in your personal email.