This topic is locked

Insert record into another table from a Custom View

7/7/2011 5:18:18 PM
PHPRunner General questions
D
DouglasB author

I have a custom view created from tbl_Doctor_Audit that is nothing but an EDIT page.
When a record is edit/updated on this view I want to insert a new record into tbl_Corrective_Action. What I want added in this new record is the field "p_ID". In the table the new record being inserted into (tbl_Corrective_Action) I also have a field named "p_ID". So I think the EVENT After Record Update I should be this:
//** Insert a record into another table ****

global $conn;

$strSQLInsert = "insert into tbl_Corrective_Action (p_ID) values (p_ID)";

db_exec($strSQLInsert,$conn);
This inserts a new record alright but the "p_ID" field in tbl_Corrective_Action is "0" instead of the "p_IS" value from tbl_Doctor_Audit so obviously I'm doing something wrong. Anyone got any advice?
What I'm REALLY trying to do is insert a new record into tbl_Corrective_Action everytime a record in tbl_Doctor_Audit is edited and the value of fields Q1, or Q2 or Q3 or Q4 equal to "2".
So that when someone edits a Doctor Audit and answers any of the 4 questions with a "2"(No) then a new record will be submitted into tbl_Corrective_action "p_ID" so then someone else can go to that Corrective Action record and input the corrective action needed.
Any help would help <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=question&id=17323&image=1&table=forumtopics' class='bbc_emoticon' alt=':)' />
Thanks.

D
DouglasB author 7/7/2011

OK, I'm an idiot. Jane and Sergey keep telling me to pay more attention to my arrays and I keep forgetting!
This problem is solved by doing an EDIT BEFORE RECORD UPDATE
global $conn;

$strSQLInsert = "insert into tbl_Corrective_Action (p_ID) values ('".$values["p_ID"]."')";

db_exec($strSQLInsert,$conn);
I still need help with Identifying the Q1 - Q4 issue though <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=59308&image=1&table=forumreplies' class='bbc_emoticon' alt=':)' />

A
Aleix 7/7/2011

Hi Douglas;
If I undertand to you ok I will try:
.- Read the fields in the events with

[indent]$values["MyFieldName"];[/indent]
.- Test it if equal to "2" whit a if and ....
I hope it help you
Aleix

D
DouglasB author 7/7/2011



Hi Douglas;
If I undertand to you ok I will try:
.- Read the fields in the events with

[indent]$values["MyFieldName"];[/indent]
.- Test it if equal to "2" whit a if and ....
I hope it help you
Aleix


Aleix,
Thanks for responding and it sounds like you are on the right track I just don't understand what you mean or rather how to implement your advice.
Let me restate the problem for clarity sake.
On my edit page in Events BEFORE UPDATE I have this statement:
global $conn;

$strSQLInsert = "insert into tbl_Corrective_Action (p_ID) values ('".$values["p_ID"]."')";

db_exec($strSQLInsert,$conn);
It works as it does insert a new record. Now I want to modify this so that it inserts a new record only if any of these fields are a value of "2"
'Was there adequate chief complaint docs for a dental emergency'

'Was there adequate oral exam documentation'

'Was the diagnostic assessment appropriate'

'Treatment proposed/rendered consistent with plan or complaint'

'Was the medication Rx type/dose/duration appropriate'

'Was informed consent obtained and signed as appropriate'

'Was the type and amount of anesthesia noted'

'Were radiographs taken adequate for diagnosis and labeled/dated'

'Where referrals given when indicated'

'Terminology used clear specific'

'Completed services noted on all areas of record and dated'

'Pre-medication documented as applicable'

'Post-operative documented as applicable'

'Next visit follow-up visit information is noted'

'Consent for general treatment is signed on fact sheet'

'Allergies noted and labeled on front of chart'

'Notes signed by doctor on signature portion of note'

'dte_Dateof Doctor_Audit'
I've tried a couple of different WHERE clauses but I always get an error so the page won't load. Something in my syntax is my guess. I'm just not formatting the where statement correctly I think.
How do I say/write/code
"global $conn;

$strSQLInsert = "insert into tbl_Corrective_Action (p_ID) values ('".$values["p_ID"]."')";

db_exec($strSQLInsert,$conn);"
BUT only if [FieldName]="2"?

A
Aleix 7/8/2011

Hi Duglas;
You can try this
// Flag down

$flag = "0";
// Look if the fieldName1 is = "2"

$field = $values["fieldName1"];

if ($field == 2)

$flag = "1";
// Look if the fieldName2 is = "2"

$field = $values["fieldName2"];

if ($field == 2)

$flag = "1";
// Repeat this with every field
// At the end, check the flag

if ($flag == 1)

{
global $conn;

$strSQLInsert = "insert into tbl_Corrective_Action (p_ID) values ('".$values["p_ID"]."')";

db_exec($strSQLInsert,$conn);

}
// End code
You can try the code with on field and if it is fine then write the rest and optimize de code
Bye
Aleix