inserting one new record in table A and update table B

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

inserting one new record in table A and update table B

Post by tlyangdicom »

Dear Sir:

I have a question to ask about phpmaker.
I created a small trophy inventory system for my class.
All the trophies are maintained in table called "trophy".
There is another table called " transaction" to keep the records of borrow-and-return.

I need to insert one transaction record and update the trophy status at the same time to avoid data inocngruence.
Every trophy has a trophyID.

While inserting a record into the transaction table, users can use ajax to fast select the record to be used.

So the codes are as follows:
( actually no idea where will be the best place to put, server or client side?)

$("input[name='x_TrophyID']").change(function () {
var selection = $(this).val();
UPDATE trophy SET Status= 1 where UID = selection
});

Any help appreciated.


kirondedshem
User
Posts: 642

Post by kirondedshem »

Read up on Server Events and Client Scripts, coz they indicate all available events and when they are executed so you can know where to place.Beleive me you will need to know

BUT in a summary: you dont have to use ajax call to update because at that time the user has not yet decided to submit the record with that particular selection. Rather, it would be better to do your custom update after you are sure a user has selected a trophy from the list and he has submited his selection to be added int the database.

For that there is an event called Row_Inserted($rsold, &$rsnew), which is fired for every table right after a record has been inserted into that table, this is where you should call your custom update from.$rsnew is an array of the record that has been inserted

So go to table transaction->click on code(server eventd, client scripts and custom templates) tab -> find fucntion called Row_Inserted($rsold, &$rsnew). put code like.

function Row_Inserted($rsold, &$rsnew) {
//read the trophy value in array
$TrophyID = $rsnew["TrophyID"];
ew_Execute("update trophy SET Status= 1 where UID = '$TrophyID' ");

}

Again read up on those event to find out what each does


tlyangdicom
User
Posts: 6

Post by tlyangdicom »

Dear kirondedshem:

You really made my day!

All work!

And also used the code for the update scenario, and works as well.

function Row_Updated($rsold, &$rsnew) {
//read the trophy value in array
$TrophyID = $rsnew["TrophyID"];
ew_Execute("update trophy SET Status= 0 where UID = '$TrophyID' ");

}

Thanks a lot!


Post Reply