SirChick Posted November 16, 2007 Share Posted November 16, 2007 Is it possible to do this : Say i got 3 fields: YesterdayProfit DayBeforeProfit ProfitToday Now in a query is it possible to move ProfitToday to become YesterdayProfit and YesterdayProfit (before the first change) to become DayBeforeProfit All in one query? Does it have a move feature that I am looking for, or do i have to obtain the values from each then INSERT in to the correct field which is the longer method.. Link to comment https://forums.phpfreaks.com/topic/77649-solved-moving-field-value-to-other-field-in-one-query/ Share on other sites More sharing options...
Barand Posted November 16, 2007 Share Posted November 16, 2007 try UPDATE mytable SET DayBeforeProfit= YesterdayProfit , YesterdayProfit = ProfitToday , ProfitToday = 0 Link to comment https://forums.phpfreaks.com/topic/77649-solved-moving-field-value-to-other-field-in-one-query/#findComment-393072 Share on other sites More sharing options...
SirChick Posted November 16, 2007 Author Share Posted November 16, 2007 <? include("include.php"); $GetCasinos = mysql_query("SELECT * FROM citycasinos"); While (mysql_fetch_assoc($GetCasinos)){ $Update = "UPDATE citycasinos SET DayBeforeProfit= YesterdayProfit , YesterdayProfit = ProfitToday , ProfitToday = 0"; $result = mysql_query($Update) or die(mysql_error()); } ?> Fatal error: Maximum execution time of 60 seconds exceeded in C:\xampp\htdocs\test2.php on line 10 Did that go into an infinite loop :S ? Just to add the query didn't work.. Link to comment https://forums.phpfreaks.com/topic/77649-solved-moving-field-value-to-other-field-in-one-query/#findComment-393081 Share on other sites More sharing options...
Barand Posted November 16, 2007 Share Posted November 16, 2007 If you have 1000 records then you are updating all 1000 of them 1000 times. All you need is my query to update the whole table. <? include("include.php"); $Update = "UPDATE citycasinos SET DayBeforeProfit= YesterdayProfit , YesterdayProfit = ProfitToday , ProfitToday = 0"; $result = mysql_query($Update) or die(mysql_error()); ?> Link to comment https://forums.phpfreaks.com/topic/77649-solved-moving-field-value-to-other-field-in-one-query/#findComment-393083 Share on other sites More sharing options...
SirChick Posted November 16, 2007 Author Share Posted November 16, 2007 well i only had one record for this test but ill give your one a try.. Link to comment https://forums.phpfreaks.com/topic/77649-solved-moving-field-value-to-other-field-in-one-query/#findComment-393086 Share on other sites More sharing options...
SirChick Posted November 16, 2007 Author Share Posted November 16, 2007 works a treat. Thankyou Link to comment https://forums.phpfreaks.com/topic/77649-solved-moving-field-value-to-other-field-in-one-query/#findComment-393087 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.