hello
i have project
have four tables :
Order >> to make order
Suppliers >> Supplier company -- each suppiler have own item
Items >> item information , price and Supplier Name
Orderitems >> to add items on order
Order (parent table) >>> Orderitems (child table)
On order table there are :
Supplier >> look up from Suppliers
ON Orderitems there are :
OrderNo >> lookup field from Order
Supplier >> look up from Suppliers
Item >> look up from Suppliers
when add item to order :
Suppliers information send to Orderitems (child table) so items drop down will show only item for Current supplier
i dont want each time add new item to order select supplier from dorpdown then select items
thanks a lot
how get value of lookup field on child table from parent table?
Re: how get value of lookup field on child table from parent table?
Here’s a possible approach to retrieving the value of a lookup field from the parent table, then using it in the child table record: In your child table hook (e.g.
In this example:
hooks/orderitems.php
), inside orderitems_before_insert
and orderitems_before_update
, retrieve the parent record's ID and then look up the needed parent field. For example:Code: Select all
function orderitems_before_insert(&$data, $memberInfo, &$args){
// 1. Get the parent “OrderNo” from the child record
$parentID = makeSafe($data['OrderNo']);
// 2. Use that ID to retrieve the “Supplier” from the parent “Order” table
if($parentID){
$parentSupplier = sqlValue("SELECT `Supplier` FROM `Order` WHERE `id`='{$parentID}'");
// 3. If we successfully retrieved the parent supplier, set it in the child record
if(!empty($parentSupplier)){
$data['Supplier'] = $parentSupplier;
}
}
return TRUE;
}
-
orderitems
is the child table. -
OrderNo
is the lookup to the parent “Order” table. -
Supplier
in the parent “Order” table is the field you need to copy or use in the child table. -
Supplier
in the child table is another lookup that you want to automatically set.

- DataTalk is an innovative AppGini plugin based on ChatGPT that allows you to interact with your AppGini database using natural language questions, without writing any SQL. Check the demo video
- Check our other plugins and get a generous discount of up to 30% when buying 2 or more plugins.
- Need personalized consulting on your specific app and customizations? Book an online call with me here.
Re: how get value of lookup field on child table from parent table?
hello
i already add code but its not working , its only work after Make save change , i can still see items for all supplier
thanks a lot
i already add code but its not working , its only work after Make save change , i can still see items for all supplier
thanks a lot