Jump to content

mysql and php help


duncan_cowan

Recommended Posts

Hi i am making a cron job that will add the value of one field in a mysql row to the value of another field and then insert the result into the row. the problem is that i want this to do it for each row and im not quite sure how. :) any help would be appreciated.Duncan Cowan

Link to comment
Share on other sites

If i understand what you said, here's the SQL solution to your question, just for future reference:

//Connection information goes here; assumed connection variable called $msa.$sql = "SELECT c1.number_column as one,c2.number_coumn as two FROM tablename c1,tablename c2";$ans = mysql_query($sql,$msa) or die(mysql_error());while($row = mysql_fetch_assoc($ans) ) {  $new = $row['one'] + $row['two'];  $sql = "INSERT INTO tablename(number_column) VALUES($new)";    mysql_query($sql) or die(mysql_error());}

That should do it if i read and understood the question right.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...