Jump to content
MakeWebGames

Cron help.


schitt

Recommended Posts

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. ;/

Link to comment
Share on other sites

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']}");
}
Link to comment
Share on other sites

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);

}

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...