Jump to content

mysql and php help


duncan_cowan
 Share

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...