| Index
» Projects
» phpMyEdit
» Forum
» Field automatically calculates and stores to DB |
 |
JackAC
Joined: 31 Jul 2012
Posts: 1
Posted: 2012-07-31 13:49
Back to top
Reply with quote
|
I'm trying to design a proof-of-concept system for our company to save quote files. I am by no means an expert when it comes to PHP or MySQL; more of an enthusiast.
I want to have a field that calculates an element of the quote and stores it to the database automatically to reduce the amount of work the staff member needs to do.
I've got a dummy field with the formula working, but it doesn't store to the database. I don't know what to do to make it. This is what I have:
| Code: |
$opts['fdd']['PV_Quote_KwHrs'] = array(
'name' => '<b>Kilowatt Hours</b>',
'select' => 'T',
'maxlen' => 100,
'number_format' => array(2, '.', ','),
'options' => V,
'sql' => '(Area / 100 * PV_Survey_Roof_Orientation * PV_Quote_KwPP)',
'sort' => true
);
|
Any suggestions? I hope I'm being clear enough - any help would be
really
appreciated.
|
doug
Joined: 10 Feb 2003
Posts: 1013
Location: Denver, Colorado (USA)
Posted: 2012-07-31 16:29
Back to top
Reply with quote
|
I can't visualize the immediate solution.
Probably it would include a trigger upon Insert and/or Update actions.
http://opensource.platon.sk/projects/doc.php/phpMyEdit/html/configuration.triggers.html
I'm not sure if upon Insert/Change the $newvals includes values for dummy fields. For debugging, you might add to your trigger file:
| Code: |
ksort($newvals);
$print_r_text = preg_replace('/\n/s', "\r\n", print_r($newvals, true));
echo !stristr($print_r_text, ']') ? '' : "\n".'<p>$newvals</p><pre>'.htmlspecialchars($print_r_text).'</pre>'; |
Reference:
| Code: |
Variables available within included triggers:
$this object reference
$this->dbh initialized 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
|
Triggers cheat sheet:
http://www.php-form-generator.com/phpmyedit/cheat-sheet/triggers.txt
|
|
Post new topic
Reply to topic
|
|
|
|