
ab5ni
Posts: 177
|
| Posted: 08/24/2010, 8:19 PM |
|
Basically, the parent is calling a pop-up that's generating a table entry, and I'm trying to pass the parent the primary key via an "After Execute Insert" CCS Event, and the parent is also making a table entry and inserting the pop-up provided primary key as a foreign key.
Currently, I'm using "SELECT last_inserted_id() as lid" MySQL statement to get the key, and then I'm using CCSetSession($last_insert_id, $lid), then picking up the key on the parent, but this "solution" seems kinda nasty and them some . As far as I know, the primary key is not available on the form, so it can't be passed via javascript to the parent. What further complicates things is there is a distinct possibility that multiple users will be entering data simultaneously, so CCGetSession() could pick up the wrong key from the pop-up (or am I missing something here?).
_________________
Randall Jouett
Amateur Radio: AB5NI
I eat spaghetti code out of a bit-bucket while sitting at a hash table! And yes, I paid for the meal in cache!
|
 |
 |
datadoit
|
| Posted: 08/25/2010, 8:02 AM |
|
Things to note: last_insert_id() will get the last key from the database
connection that's open by the user. Sessions are user browser session
specific. The only issue you would have there is if someone has
multiple browser windows open on their computer.
|
|
|
 |
ab5ni
Posts: 177
|
| Posted: 08/26/2010, 12:10 PM |
|
That's what I was figuring, datadoit, but wasn't absolutely positive things worked that way. No matter. It still doesn't work . Have a grid, click on addnew, first pop-up (a maint/record window generated by CCS) pops up, add all info for the record, and then click on a checkbox that pops up another maint/record window that adds a record and tries to send the primary key back to the first popup via the following code called in the After Insert Event:
global $last_insert_id;
$SQL = "SELECT last_insert_id() as lid";
$db->query($SQL);
if($db->next_record()) {
$lid = $db->f("lid");
CCSetSession($last_insert_id,$lid);
}
After this code is executed and the window is closed, I try to pick up the session value via CCGetSession($last_insert_id) in the Before Insert event and assign the value returned to a hidden form value associated with the record. When I hit add to insert the new record, which hopefully contains the foreign key picked up via $last_insert_id, CCS comes back as says "rental_id can not be null" and doesn't add the new record. This is a correct statement, because this is a foreign key associated with the new record I'm trying to insert and can't be null. The record is not inserted, and MySQL doesn't allow the foreign key to be null.
Anywho, this has been driving me nuts for the last few days. As far as I can tell, it should work, but for some unknown reason to me, it doesn't. HELP!!!
_________________
Randall Jouett
Amateur Radio: AB5NI
I eat spaghetti code out of a bit-bucket while sitting at a hash table! And yes, I paid for the meal in cache!
|
 |
 |
|

|
|
|
|