tonymcc
Joined: 15 Jan 2009
Posts: 6
Posted: 2009-01-15 07:31
Back to top
Reply with quote
|
I am using version 5.7.1 right now. (I just purchased MFG but haven't gotten it yet). However, I having difficulty getting a trigger to execute at all.
The examples don't actually have much detail on how to use the triggers or enable them.
The code looks like this right now:
| Code: |
<snip>
$opts['triggers']['update']['after'] = 'updatelastid.TAA.inc';
// Now important call to phpMyEdit
require_once 'phpMyEdit.class.php';
new phpMyEdit($opts);
<snip>
|
It does not ever run. What am I doing wrong? Everything else I've done so far is working great.
For test purposes the trigger code itself looks like this:
| Code: |
<?php
print '<br/> TRIGGER CODE EXECUTED <br/>';
return(true);
?> |
By the way.. I realize that triggers are for invisible actions, but I was not having any luck, so, just as a test I put the print call in.
What I really want to do is update a separate table with the value of the an assigned ID # + 1, I use the table lookup to get the next number and on save in Add Mode only I will increment that number. For technical reasons it has to be a sequence table not an integrated AUTO_INCREMENT field.
|
tonymcc
Joined: 15 Jan 2009
Posts: 6
Posted: 2009-01-15 10:17
Back to top
Reply with quote
|
I have managed to get the call to work as a 'php' field option, which proves to me that at least the script will run and update the table I want. However treating it like a trigger does not.
Using a direct 'php' action measn I would have to write all the pre/post/cancel logic. I'd much prefer the trigger to work.
You can see below that I am using a values table lookup in 'ADD' mode to get the next ID number, so I just need to increment it on successful save for specific type of 'parrent' record.
| Code: |
$opts['fdd']['PrimaryID'] = array(
'name' => 'Primary Member ID',
'select' => 'T',
'maxlen' => 10,
'sort' => true,
'values|A' => array(
'table' => 'coopids',
'column' => 'NextID',
'filters' => 'IDName = "PRIMARY" '), //lookup the last ID in ADD mode
'php' =>'updatelastid.php'
);
|
Any help you may have would be appreciated.
|
doug
Joined: 10 Feb 2003
Posts: 1013
Location: Denver, Colorado (USA)
Posted: 2009-01-15 21:41
Back to top
Reply with quote
|
If you want the trigger to grab the ID of the last record added (in Add mode) then you need ['insert']['after'] instead of ['update']['after']
Posting the complete trigger would be helpful in understanding the goal.
|
tonymcc
Joined: 15 Jan 2009
Posts: 6
Posted: 2009-01-15 21:59
Back to top
Reply with quote
|
At this point the trigger won;t execute not matter what I put in it, But here's the code I used fpr the 'php' field option call
| Code: |
<?php
// TRIGGER TO UPDATE LAST ID
$this->myquery("UPDATE `coopids` SET `LastID` = `LastID` +1 WHERE `IDName` = 'PRIMARY'");
return(false);
?> |
As you can see I don't need to know the internal record ID of the current record, I just need to increment a field in a separate table AFTER as succesful save in the main table.
I do need to be able, eventually, to check that the value of a field called 'Relationship' is equal to 'P' as a pre-req to incrementing the LastID field.
This spinnet is incomplete as I am trying to just prove that it will execute as a trigger at all right now and it does not.
--Tony
| doug wrote: |
If you want the trigger to grab the ID of the last record added (in Add mode) then you need ['insert']['after'] instead of ['update']['after']
Posting the complete trigger would be helpful in understanding the goal. |
|
doug
Joined: 10 Feb 2003
Posts: 1013
Location: Denver, Colorado (USA)
Posted: 2009-01-15 22:20
Back to top
Reply with quote
|
Build in some error checking?
| Code: |
if($this->myquery("UPDATE `coopids` SET `LastID` = `LastID` +1 WHERE `IDName` = 'PRIMARY'")){
return true;
}else{
echo "\n".'<p>'.mysql_error().'</p>';
echo "\n".'<a href="javascript:history.go(-1)" onmouseover="self.status=document.referrer;return true">Go Back</a>';
@mysql_close($this->dbh);
require_once('./inc/footer.php');
exit;
} |
|
doug
Joined: 10 Feb 2003
Posts: 1013
Location: Denver, Colorado (USA)
Posted: 2009-01-15 22:21
Back to top
Reply with quote
|
Variables available within a trigger include:
$this - object reference
$this->dbh - nitialized MySQL database handle
$this->key - primary key name
$this->key_type - primary key type
$this->key_delim - primary key deliminator
$this->rec - primary key value (update and delete only)
$newvals - associative array of new values (update and insert only)
$oldvals - associative array of old values (update and delete only)
$changed - array of keys with changed values
|
tonymcc
Joined: 15 Jan 2009
Posts: 6
Posted: 2009-01-15 22:24
Back to top
Reply with quote
|
Well, I'll be. Changing it to [insert][after] and this minor tweak below (thanks to the mfg txt examples) seems to have done the job!
| Code: |
<?php
// TRIGGER TO UPDATE LAST ID
if($newvals['Relationship'] == 'P') {
$this->myquery("UPDATE `coopids` SET `LastID` = `LastID` +1 WHERE `IDName` = 'PRIMARY'");
return(false);
}
?> |
NOW I'll add the error checking ... I try and keep it simple to start with, thanks for the help.
|
|
Post new topic
Reply to topic
|