badurek Posted May 3, 2013 Share Posted May 3, 2013 (edited) Hi guys, i add this code to cron_fivemins to get randomly the sell prices of drugs. But is missing the way to identify the drugid because all drugs get randomly same price. Someone can help me with this? Thx, and srry for bad english ;p $chance = rand(50,100); $db->query("UPDATE drugs SET itmsellprice=$chance"); Edited May 3, 2013 by badurek Quote Link to comment Share on other sites More sharing options...
KyleMassacre Posted May 3, 2013 Share Posted May 3, 2013 Im not exactly sure on what you want to accomplish here, a little more info would help a bit. Also you have a fetch_row but its not being used. Can you please try to explain in a little more detail Quote Link to comment Share on other sites More sharing options...
badurek Posted May 3, 2013 Author Share Posted May 3, 2013 I want get random sell prices for drugs, and i can do this with this code, but all drugs get the same random price. I need each drug get random price. I believe just need to get the id of each drug to work, but i dont know do this. Quote Link to comment Share on other sites More sharing options...
sniko Posted May 3, 2013 Share Posted May 3, 2013 $ids = array(1,2,3,4,5,6); //Specific ID's that you want to change the price of foreach($ids as $id) { $chance = mt_rand(50,100); $db->query("UPDATE `drugs` SET `itmsellprice`={$chance} WHERE `itmid`=$id"); //I assume the column id `itmid`, as you've adopted the column names from `items` } Quote Link to comment Share on other sites More sharing options...
KyleMassacre Posted May 3, 2013 Share Posted May 3, 2013 (edited) $ids = array(1,2,3,4,5,6); //Specific ID's that you want to change the price of foreach($ids as $id) { $chance = mt_rand(50,100); $db->query("UPDATE `drugs` SET `itmsellprice`={$chance} WHERE `itmid`=$id"); //I assume the column id `itmid`, as you've adopted the column names from `items` } Thats good and all but what about for newbies or for people that forget about the manually entered array and create a new drug? How about: $ids = $db->query("select id from from drugs"); foreach($ids as $id) { $rand = mt_rand(50, 100); $update = $db->query("update drugs set itemsellprice = {$rand} where id = {$id}"), } Edited May 3, 2013 by KyleMassacre fix a booboo 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.