This topic is locked

Lookup Tables

2/13/2008 4:07:11 PM
PHPRunner General questions
M
mrphp author

I have an ADD page that has 2 related fields. One is "JobNumber" and one is "JobName". I have JobNumber setup as a lookup table that gets its number from a database of job numbers. What I would like to do is have the "JobName" field automatically fill in with the corresponding name that goes with the JobNumber selected (from the database of job numbers). Is this possible?
Thanks for the help.

J
Jane 2/14/2008

Hi,
use dependent dropdown boxes for this purpose.
Also I recommend you to have a look at the "How to setup dependent dropdown boxes on Edit/Add pages" PHPRunner tutorial:

http://www.xlinesoft.com/phprunner/php-database.htm

M
mrphp author 2/14/2008

Hi,

use dependent dropdown boxes for this purpose.
Also I recommend you to have a look at the "How to setup dependent dropdown boxes on Edit/Add pages" PHPRunner tutorial:

http://www.xlinesoft.com/phprunner/php-database.htm


Hi Jane,
I watched the tutorial but I'm still having problems. I have 2 tables:
jobnumbers with fields "number" (which is also the ID field) and "name" and
subcontacts with fields "subcontactnumber" (ID field), "jobno" and "jobname".
Now, I've setup a lookup table for field "jobno" to pull its information from table jobnumbers with link field "number" and field name "number". This works. I'd like the "jobname" field to automatically populate with the corresponding name in the "name" field from the same record. Each job number has only one job name in the jobnumbers table. If that can't be done then I would be OK with a dropdown box that only contained the correct job name for that number but I don't seem to be able to get that to work. How should the lookup table be setup for the "jobname" field?
I'm not sure I'm being very clear so I hope you can follow what I'm trying to do.
Thanks for you help, again.

J
Jane 2/14/2008

Hi,
JobName is redundant field in the subcontacts table.

I recommend you to use only jobno field on the add/edit page of subcontacts table and fill it with correct ID from jobnumbers table.
Setup number as link field and name as display field for jobno field on the "Edit as" settings dialog on the Visual Editor tab.
Also you can fill jobname field with correct value in the Before record added event on the Events tab.

Here is a sample:

global $conn;

$str = "select name from jobnumbers where IDfield=".$values["jobno"];

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

if ($data = db_fetch_array($rs))

$values["jobname"] = $data["name"]



where IDfield is your actual field name.

M
mrphp author 2/14/2008

Hi,

JobName is redundant field in the subcontacts table.

I recommend you to use only jobno field on the add/edit page of subcontacts table and fill it with correct ID from jobnumbers table.
Setup number as link field and name as display field for jobno field on the "Edit as" settings dialog on the Visual Editor tab.
Also you can fill jobname field with correct value in the Before record added event on the Events tab.

Here is a sample:
where IDfield is your actual field name.


I entered your code as custom code on the "Add Page: Before Process" as shown below:
// Parameters:

// $values - Array object.

// Each field on the Add form is represented as a 'Field name'-'Field value' pair
//** Custom code ****

// put your custom code here

global $conn;

$str = "select name from jobnumbers where number=".$values["jobno"];

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

if ($data = db_fetch_array($rs))

$values["jobname"] = $data["name"]
return true;
// return true if you like to proceed with adding new record

// return false otherwise
Now I get the following error when opening the web page:
"Parse error: parse error, unexpected T_RETURN in /var/www/html/phprunner/sub/include/sub_events.php on line 81"
Line 81 is the line that contains "return true;"
Are you willing to keep helping me?

J
Jane 2/15/2008

Sorry for my fault.

Here is the correct code:

global $conn;

$str = "select name from jobnumbers where number=".$values["jobno"];

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

if ($data = db_fetch_array($rs))

$values["jobname"] = $data["name"];
return true;