schitt Posted March 19, 2010 Share Posted March 19, 2010 Lets say my database is has these values buy min, buy max, buy price, sell min, sell max, sell price i want to run a cron every hour (yes i want to make the market fluctuate) , to take the buy min/buy max, and random between them 2 numbers, and set that into buy price.. same for sell.. which would be the same code i guess.. how would i set that up, for say... 50 tables? im sure the query isnt a long one,but for the life of me, i cant figure this out. ;/ Quote Link to comment Share on other sites More sharing options...
schitt Posted March 20, 2010 Author Share Posted March 20, 2010 anyone? Quote Link to comment Share on other sites More sharing options...
Analog Posted March 20, 2010 Share Posted March 20, 2010 Here is a start for ya.. $q = mysql_query("SELECT itmid, minSell, maxSell FROM table"); while($x = mysql_fetch_array($q)) { $sp = rand($x['minSell'],$x['maxSell']); mysql_query("UPDATE table SET sellPrice = $sp WHERE itmid = {$x['itmid']}"); } Quote Link to comment Share on other sites More sharing options...
Noelle Posted March 23, 2010 Share Posted March 23, 2010 Slightly different style $q_data = sprintf('select itmid, minSell, maxSell FROM table'); $r_data = $db->query($q_data); while(list($id,$min,$max) = mysql_fetch_array($r_data)) { $rand_price = mt_rand($min,$max); $q_update=sprintf('update table set sellPrice = %d where itmid = %d',$rand_price,$id); $db->query($q_update); } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.