This topic is locked

Updating Entire Table

7/17/2007 5:15:07 PM
PHPRunner General questions
G
garivera author

I want to update my entire table based on a common field
For example, I have a table with 3 fields (contractnumber), (programmanager), (enddate).
Suppose I have 1,000 records but only 100 records with the same contract number, programmanager, enddate. Instead of editing each record (up to 100) one by one, I want to edit one record based on (contractnumber) and change (programmanager) and (enddate) and apply those changes to the rest of the 99 similar records.
I was using before edit event, but I cant get it to work. If I change &values['programmanager'] to 'whatever', this works but writes whatever to all of the records. I need it to be dynamic.
function BeforeEdit($values)

{

global $conn;

$strSQLInsert = "update table set programmanager = &values['programmanager'] where contractnumber = $values['contractnumber']";

db_exec($strSQLInsert,$conn);

}
Thanks in advance
Gabe

J
Jane 7/18/2007

Gabe,
try to use following code:

function BeforeEdit($values)

{

global $conn;

$strSQLInsert = "update table set programmanager = '".$values["programmanager"]."' where contractnumber=".$values["contractnumber"];

db_exec($strSQLInsert,$conn);

}

G
garivera author 7/18/2007

That Worked,
Thanks
Gabe

G
garivera author 7/19/2007

That Worked,

Thanks
Gabe


Can someone help me with my code, I cant get it to work. Everything before the and seems to work just fine but once I add the and with everything after it, thats where it breaks.
global $conn;

$strSQLInsert = "update chartofaccounts set EndDate = '".$values["EndDate"]."' where BANR_FUND=".$values["BANR_FUND"]" and BANR_ORG=".$values["BANR_ORG"]" ;

db_exec($strSQLInsert,$conn);
I am getting the following error

Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING in /srv/www/business/proposal3/include/Filter_End_Date_events.php on line 98
Thanks in advance

Gabe

2945 7/19/2007

You have a typo in the line...
$strSQLInsert = "update chartofaccounts set EndDate = '".$values["EndDate"]."' where BANR_FUND=".$values["BANR_FUND"]" and BANR_ORG=".$values["BANR_ORG"]" ;

db_exec($strSQLInsert,$conn);
Should be...
strSQLInsert = "update chartofaccounts set EndDate = '".$values["EndDate"]."' where BANR_FUND=".$values["BANR_FUND"]." and BANR_ORG=".$values["BANR_ORG"]" ;

db_exec($strSQLInsert,$conn);
Simple missing full stop delimeter...

G
garivera author 7/20/2007

You have a typo in the line...

$strSQLInsert = "update chartofaccounts set EndDate = '".$values["EndDate"]."' where BANR_FUND=".$values["BANR_FUND"]" and BANR_ORG=".$values["BANR_ORG"]" ;

db_exec($strSQLInsert,$conn);
Should be...
strSQLInsert = "update chartofaccounts set EndDate = '".$values["EndDate"]."' where BANR_FUND=".$values["BANR_FUND"]." and BANR_ORG=".$values["BANR_ORG"]" ;

db_exec($strSQLInsert,$conn);
Simple missing full stop delimeter...


There was still a problem, but you pointed me in the right direction. This is the final one that worked.
$strSQLInsert = "update chartofaccounts set EndDate = '".$values["EndDate"]."' where BANR_FUND=".$values["BANR_FUND"]." and BANR_ORG=".$values["BANR_ORG"] ;
G