Skip to main content
Topic: Code snippets usage for Page Events (Read 1371 times) previous topic - next topic

Code snippets usage for Page Events

Hello,
I have been trying to implement an automatic update on a field without success. I have a table “equipments” that has the fields: “code” and “type” (see bellow). The field “type” is always a combination of two letters, like “EP” or “PR”. I want to generate a sequential code field value after the user has entered the type. For that I need to get an array with all the code values for the type entered. I have been using the page events feature in PHPRad adding the code bellow to the equipments table in the AfterAdd session, but it doesn't seem to work. How to use the code snippets correctly for that? Thanks

Table:
equipments
-----------------
|  code  | type |
-----------------
| EP-001 | EP   |
| PR-001 | PR   |
| PR-002 | PR   |

Code:
$params  = array($rec_id);
$codes = $db->rawQuery("SELECT code FROM equipments WHERE type = '" . $modeldata['type'] . "'", $params);

 

Re: Code snippets usage for Page Events

Reply #1
this should be what you actually want to do
Code: [Select]
$params  = array($modeldata['type'] );
$codes = $db->rawQuery("SELECT code FROM equipments WHERE type = ?", $params);