This topic is locked

Grab field data on load

7/24/2014 3:13:52 PM
PHPRunner General questions
B
bencroftweb author

Hi
This is probably a simple one but I want to insert data from one table to another when creating a new record.
i.e
Tax Rate is in table A
Table B is a fill out form
When clicking Add New I want to grab the Tax Rate from Table A and enter it into Table B
Any ideas?
I'm currently using a lookup but it feels a little clunky and adds an unnecessary click for every new record.
Many thanks
Ben

S
stiven 7/24/2014

Hey,
On the add page process record value event from table B you can insert this code.



global $conn;
$sql = "SELECT taxratetableA FROM tableA ";//change column name and add where clause if you need to

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

$data = db_fetch_array($rs);
$values['taxratetableB'] = $data['taxratetableA']; //adjust column names to your needs.
B
bencroftweb author 7/25/2014

That worked brilliant!! Thank you so much!!
I don't suppose you know how to filter to ID - ie check the ClientID to decide which taxrate.
Thanks



Hey,
On the add page process record value event from table B you can insert this code.



global $conn;
$sql = "SELECT taxratetableA FROM tableA ";//change column name and add where clause if you need to

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

$data = db_fetch_array($rs);
$values['taxratetableB'] = $data['taxratetableA']; //adjust column names to your needs.


S
stiven 7/25/2014

It is possible to filter by the clientID, just add the were clause to the statement, but where would you get the clientID from?



global $conn;
$sql = "SELECT taxratetableA FROM tableA WHERE clientID = '".$_SESSION['CLIENTID']."'";//you could store the client ID in a session if you are doing it by user logged in

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

$data = db_fetch_array($rs);
$values['taxratetableB'] = $data['taxratetableA']; //adjust column names to your needs.