HELP with SELECT then UPDATE

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
Xserve2
Forum Newbie
Posts: 1
Joined: Fri Dec 16, 2005 5:51 am

HELP with SELECT then UPDATE

Post by Xserve2 »

HawleyJR | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]

I have a db where the data in 3 of the columns needs to be added and the result placed in another column

Here is my code :

Code: Select all

$query1= "SELECT * FROM `costanal2` WHERE pnum='MEGAMT'";		
$result1 = mysql_query($query1) or die('ERROR: Query failed:<br><i>'.$query1.'</i><br><b>'.mysql_errno().'</b><br>'.mysql_error());
$total = mysql_num_rows($result1);
$t=-1;
while(++$t < $total){
    $result =mysql_query('SELECT ACOMM,ACERT,ACTUL,CSTID FROM `costanal2`  WHERE "PNUM" = "MEGAMT";')or die('Error in ATEMP.<br>' . mysql_error());
    $end_col= mysql_result($result1,$t,'ACOMM')+mysql_result($result1,$t,'ACERT')+mysql_result($result1,$t,'ACTUL');
    
    
    
    $match = mysql_result($result1,$t,'CSTID');
   
    $doit=mysql_query('UPDATE `costanal2` SET ATEMP = "$end_col" WHERE CSTID = "$match"')or die('Error in updating ATEMP.<br>' . mysql_error());
All i get in ATEMP is a 0 ( zero)

Yet if I echo $match and $ end_col they have the correct values - I don't get any error messages

Bill

HawleyJR | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
Post Reply