This topic is locked
[SOLVED]

 How To Auto Fill A Linked Record (Invoices And Jobs)

1/7/2013 5:05:21 PM
PHPRunner General questions
S
snape author

Hi,
I can't remember how I found this solution as it was a little while ago but I've just realised it's not working.
To explain, when I add a new invoice to a job I want the field which shows the linked job reference number to be filled automatically.
In the editor for invoices on the add and edit pages for that field, in the 'view as' section I have this code:
/

global $dal, $strTableName;

echo $data["jobID"]." ";

if ($_SESSION[$strTableName."_masterkey1"])

{

$tblMaster = $dal->Table("joblist");

$rs = $tblMaster->Query("jobID=".$_SESSION[$strTableName.

"_masterkey1"],"");

if ($data = db_fetch_array($rs))

{

echo ($data["jobName"]);

}

}
/
The problem I have is that it is assigning a number which is one less than the correct value. Ie it is assigning 24 when it should be assigning 25.
Could anybody possibly let me know how to amend the code to display the correct value?
Thanks very much for any help with this.
Kind regards
Spencer

Sergey Kornilov admin 1/7/2013

It looks a bit confusing to me. This code is not assigning anything, it simply displays data from another table. I'm not sure how this code can "assign" something. It's also not clear if you talking about adding data or about displaying data.

S
snape author 1/7/2013



It looks a bit confusing to me. This code is not assigning anything, it simply displays data from another table. I'm not sure how this code can "assign" something. It's also not clear if you talking about adding data or about displaying data.


Thanks for your response...
Yes sorry I haven't been clear enough.
When I add/edit an invoice this field needs to be filled in so I know which job it is linked to. I believe this code simply tries to work what the value should be and fills it in for me. I have made this read only so whoever creates the new invoice can't accidentally over type with the incorrect value.
The value of the field is assigned when the new recorded is added or amended.
I hope that clears it up a bit.
Thanks again
Spencer

Sergey Kornilov admin 1/7/2013

You can simply create master-details relationship between Jobs and Invoices tables. Corresponding link field in Invoices table will be filled with master key value from Jobs automatically.

S
snape author 1/8/2013



You can simply create master-details relationship between Jobs and Invoices tables. Corresponding link field in Invoices table will be filled with master key value from Jobs automatically.


I'm not sure exactly why I've done it this way.
It may become more obvious as I try to implement the solution.
I'm not sure if your suggestion works due to the need for this to be a many-to-one-relationship.
There can be multiple invoices for each job. Could you point me in the right direction for setting this up please?

Sergey Kornilov admin 1/8/2013

Well, I just did. You can simply create master-details relationship between Jobs (master) and Invoices (details) tables. Corresponding link field in Invoices table will be filled with master key value from Jobs automatically.

S
snape author 1/8/2013



Well, I just did. You can simply create master-details relationship between Jobs (master) and Invoices (details) tables. Corresponding link field in Invoices table will be filled with master key value from Jobs automatically.


Ah I've just worked out what the problem was, I had a duplicate job number in my own references.
Thanks for your help.
Spencer