How to update detail table automatically when inputting data in master detail?

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
diazwahyunugraha
User
Posts: 4

How to update detail table automatically when inputting data in master detail?

Post by diazwahyunugraha »

Is it possible to update the detail table automatically when inputting data in the master detail?

I have a master table with an x_cardnumber column then in the details there is also an x_cardnumber column with multiple records.

How do I do this when I input data in the x_cardnumber master table. the x_cardnumber in the detail table is also updated automatically


mobhar
User
Posts: 11726

Post by mobhar »

Your case is a bit confusing. When you said inputting data in master table, then it means there are no data yet both for your master and detail table. How can you update the data in detail table, then?


diazwahyunugraha
User
Posts: 4

Post by diazwahyunugraha »

Because i already have master table which is summary from detail table, but in the detail table there is blank field that must multiple update by field in master table

Master table:
Name, address, sumofbuy, id_card

Detail table:
Name, address, buy, id_card

Which is master table already summaries by name and by address

I need to fill id card (multiple) in detail table automaticly just by input id_card in master table


apis
User
Posts: 124

Post by apis »

use Server Event table specific row inserted like this:

$myResult = ExecuteStatement("UPDATE MyTable SET Field1=Value1, Field2=Value2, Field3=Value3 WHERE MyField=XXX");// Row Inserted event

and if you want to input multi values use concat function


mobhar
User
Posts: 11726

Post by mobhar »

diazwahynugraha wrote:

I need to fill id card (multiple) in detail table automaticly just by input id_card in master table

Then you should use Row_Updated (not Row_Inserted) server event that belongs to your master table in order to update the related data in your detail table.


diazwahyunugraha
User
Posts: 4

Post by diazwahyunugraha »

// Row_Updated event for MasterTable
function Row_Updated(&$rsold, &$rsnew) {
    // Check if id_card field is updated
    if ($rsold['id_card'] != $rsnew['id_card']) {
        // Perform update in DetailTable based on the updated id_card value
        $detailUpdateQuery = "UPDATE DetailTable SET id_card= '{$rsnew['id_card']}' WHERE name= '{$rsnew['name]}' AND address= '{$rsnew['address]}' ";
        Execute($detailUpdateQuery);
    }
}

this error


gopalverma1
User
Posts: 10

Post by gopalverma1 »

Refer Documentation : Field Setup ->Client Side Event ->Example 1 & Example 2

IN MASTER TABLE FIELD : x_cardnumber (Client Side Event)

{
    "change keyup": function(e) {
		$('[data-table=DETAILTABLE][data-field=x_cardnumber]').trigger("change");
    }
}

IN DETAIL TABLE : x_cardnumber (Client Side Event)

{ // keys = event types, values = handler functions
    "change keyup": function(e) {
		var xcardnumber = myform.elements["x_cardnumber"].value;
        var $row = $(this).fields(); // Get an object of all fields, each property is a jQuery object of the input element(s) of a field
        //var st = $row["UnitPrice"].toNumber() * $row["Quantity"].toNumber() * (1 - $row["Discount"].toNumber()); // Convert to number and calculate
        $row["x_cardnumber"].value(xcardnumber); // Set result to a field
    }
}

Think this will help


mobhar
User
Posts: 11726

Post by mobhar »

There is no need to add curly brackets in your SQL, so try this:

"UPDATE DetailTable SET id_card='".$rsnew['id_card']."' WHERE name='".$rsnew['name]."' AND address='".$rsnew['address]."'"

It that SQL doesn't work, then you need to re-evaluate your data while updating master record, especially for name and address fields, whether it will be changed or not... if those fields remain same, then you may try:

"UPDATE DetailTable SET id_card='".$rsnew['id_card']."' WHERE name='".$rsold['name]."' AND address='".$rsold['address]."'"


diazwahyunugraha
User
Posts: 4

Post by diazwahyunugraha »

Fatal error: Call to undefined function Execute() in ...

i dont know why


mobhar
User
Posts: 11726

Post by mobhar »

Try to use ExecuteStatement instead of Execute.


Post Reply