Update one Field from another

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
nserpiot
User
Posts: 49

Update one Field from another

Post by nserpiot »

I have the below tables:

Initial

City,Phone

ShiftsMap

City,TimeID, TimePeriod

Shifts_Defined

City,Phone,TimeID, TimePeriod

I want upon selecting City in the 3rd table to see the available Phones and available TimeID and TimePeriod

So, parent Field : CITY and childs: Phone, TimeID, TimePeriod. The first two (Phone,TimeID) are SELECT fields and the third (TimePeriod) I want to be automatically filled-up.
How can I make it ?


scs
User
Posts: 694

Post by scs »

Do this in Row_Inserted and/or Row_Updated with ew_Execute("update shiftmap set [fields need to update] where [conditions];");

But there might be some other conditions. Otherwise entire table will be updated too.


mobhar
User
Posts: 11744

Post by mobhar »

You may simply use "Auto fill". Read about it under "Field Setup" topic in the PHPMaker help file.


nserpiot
User
Posts: 49

Post by nserpiot »

I have used AutoFill, but it produces errors, when I have a chain or Parent/Child. (How many of these is safe to have?)
So, please describe me an example of the next, ew_Execute("update shiftmap set [fields need to update] where [conditions];"); since all the time I get syntax MySQL errors, while manual run is OK.
Also, please explain if Row_Inserted or Inserting in needed.

It's been a long time, that I've been trying this and no results seen.

My example: Hospitals On Duty

ew_Execute("UPDATE hosp_shifts SET Phone = (select Phone from hosp_initial WHERE HospName=" . $row["HospName"]);


mobhar
User
Posts: 11744

Post by mobhar »

What error message did you see? This will help us to find out the solution.

nserpiot wrote:
ew_Execute("UPDATE hosp_shifts SET Phone = (select Phone from hosp_initial WHERE
HospName=" . $row["HospName"]);

  1. Wrong syntax; double check the SQL above, it seems you missed the closing bracket.
  2. Make sure that SQL can be execute properly by using your database manager before implementing into server event.
  3. There is no $row context in "Row_Updated" or "Row_Inserted" server event. Use either $rsold or $rsnew instead.

Post Reply