duncan_cowan Posted September 29, 2007 Share Posted September 29, 2007 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 More sharing options...
duncan_cowan Posted September 30, 2007 Author Share Posted September 30, 2007 doesnt matter I worked it out, it was quite simple really i just loop it for every row! The only thing is im not sure how well it will cope with lots of rows but I will soon find out!! Link to comment Share on other sites More sharing options...
jhecht Posted October 4, 2007 Share Posted October 4, 2007 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.