![]() |
HJB 3/14/2017 |
Hello, after i update Table1 i need to insert ALL records to table2 BUT first need to delete previous records exists in Table2 with same EnquryLink. INSERT query below works fine and do the job : $strSQLInsert = "insert into tblordersupplydetails (VesselDept, EnquryLink, ShortCode, Description, SupplierLink, UnitLink, Quantity, Curr, Rate, ForeignUnit, Discount, ForeignUnitFinal, ForeignTotal, USDUnit, USDTotal, ApproveFlag) values ('".$values['VesselDept']."','".$values['EnquryLink']."','".$values['ShortCode']."','".$values['Description']."' ,'".$values['Supplier1']."','".$values['Unit1']."','".$values['Quantity1']."' ,'".$values['Curr1']."','".$values['Rate1']."','".$values['ForeignUnit1']."' ,'".$values['Discount1']."','".$values['ForeignTotal1']."','".$values['USDUnit1']."','".$values['USDTotal1']."' ,'".$values['Project Status']."','1') " ; CustomQuery($strSQLInsert); However when i add delete query before the above INSERT query : $sql4 = "DELETE FROM tblordersupplydetails WHERE EnquryLink=".$values["EnquryLink"]; CustomQuery($sql4); records are DELETED as they should BUT the INSERT query insers only 1 record from table 1 to table 2. Can someone assist ? thanks in advance.
|
![]() |
Sergey Kornilov admin 3/14/2017 |
Not sure I understand the question. That INSERT SQL query is supposed to insert a single record and I'm not sure how it can insert two records. |
![]() |
HJB 3/14/2017 |
https://xlinesoft.com/phprunner/docs/custom_add.htm'>https://xlinesoft.com/phprunner/docs/custom_add.htm ... for inspiration purposes only.
global $dal;
|
C
|
chrispa author 3/15/2017 |
Example ( ex https://xlinesoft.com/phprunner/docs/custom_add.htm ) Lets consider the situation when records are never added directly to the main table (e.g. Cars). Instead, records are added to the temporary TempCars table and then moved to the main Cars table once approved by admin. In this case the following code in CustomAdd event will do the job: global $dal;
|
![]() |
HJB 3/15/2017 |
thank you - however what i want to complete is the following . have tables tblrequisitiondetails and tblordersupplydetails on tblrequisitiondetails i use update 'Update selected' feature so when i complete an update of varioues field i need the script above to remove records from tblordersupplydetails and insert the new updated records . I have manage half part like without delete sql above - insert working fine but if i have it like that dublicate records are being created each time i update records in tblrequisitiondetails. so in summary insert to other table records updated working fine without DELETE sql - when i add DELETE sql to avoid dublicates then only 1 record is beign inserted rathen than 10 or 20 etc. thanks in advance.
|
C
|
chrispa author 3/17/2017 |
Got your point, so, view the following for inspiration purposes: http://stackoverflow.com/questions/21189466/copy-and-delete-data-from-one-table P.S. Throughout the past weeks there had been several forum issues where people want to DELETE while HIDE is the answer. Say, EASY IS FIRST is and shall remain my biz motto. Example, you make TWO tables and hence you complicate things, ending up in coding problems. I would only make ONE table (to get updated by whatsoever means, with finally a "done or executed or else" field) where "done or executed or else" expression would be placed inside the FILTER area of SQL query then, HIDING (rather than to DELETE) such records where the appropriate FILTER CRITERIA is met. In other words, what you try is to saddle a horse from the rear, getting somehow stricken by code-ropes of all kinds during the saddling process.
|