grlayouts Posted June 13, 2008 Share Posted June 13, 2008 I have a market game that depending on the ammount of product on the market depends on the price. but here's the thing what i want it to do 1. it keep the price of the drugs between 100-200 2. if someone sells another product for example steaks it boosts the price for everything. the code works but i dont know how to acheive what i want <? include('config.php'); $q2 = mysql_fetch_row(mysql_query("SELECT SUM(drugs) FROM players;")); function price ($q) { if ($q > 1000000) return 25; return ceil($q * -275 / 1000000) + 300; } $qtys = $q2; foreach ($qtys as $q) { echo "$q :" . price($q) . '<br>'; } mysql_query('UPDATE players SET drugs = drugs + (drugfact*2), dpayout = (drugfact*2);'); mysql_query('UPDATE players SET credits = credits - (employees*wages)'); $sql = "UPDATE price SET cost = $q where ITEM = 'drugs'"; mysql_query($sql) or die($sql . ' : ' . mysql_error()); ?> Quote Link to comment Share on other sites More sharing options...
DarkWater Posted June 13, 2008 Share Posted June 13, 2008 We have no idea what this code is doing (we have no database schema), and we are NOT your PHP slaves. Go to the freelance forum if you want someone to "achieve what you want". We can help if you provide some more information and actually try to do it yourself. Quote Link to comment Share on other sites More sharing options...
grlayouts Posted June 13, 2008 Author Share Posted June 13, 2008 ok simply.. i want the ceil to range between 1-200. { if ($q > 1000000) return 25; return ceil($q * -275 / 1000000) + 300; } $qtys = $q2; foreach ($qtys as $q) { echo "$q :" . price($q) . '<br>'; Quote Link to comment Share on other sites More sharing options...
DarkWater Posted June 13, 2008 Share Posted June 13, 2008 What do you mean by "I want q"? That makes no sense. =/ Quote Link to comment Share on other sites More sharing options...
grlayouts Posted June 13, 2008 Author Share Posted June 13, 2008 i dont want someone to write it for me. i want to know how to range the ceil from 1-200 Quote Link to comment Share on other sites More sharing options...
DarkWater Posted June 13, 2008 Share Posted June 13, 2008 I didn't think it was that hard to say what you want done. You STILL aren't accurately describing it. Do you even know what ceil() is? =/ Quote Link to comment Share on other sites More sharing options...
grlayouts Posted June 13, 2008 Author Share Posted June 13, 2008 its for rounding to a whole number. I wrote it. ok.. $q2 takes the sum of the product which is drugs at the moment. if there is over 100000 then it works out a price for selling the product. what i want to do is when the price is worked out for the product i want to limit it between 1-200 just now im getting huge results and the ammount of the product sum is huge. hows that? Quote Link to comment Share on other sites More sharing options...
DarkWater Posted June 13, 2008 Share Posted June 13, 2008 if ($price > 200) { $price = 200; } Instead of returning a calculation, store it in a variable so you can work with it. Quote Link to comment Share on other sites More sharing options...
grlayouts Posted June 13, 2008 Author Share Posted June 13, 2008 too simple for what i will be adding later. can i set the value as a percentage. ie if 10000 drugs price is 20% of 200. if 20000 drugs price is 30% of 300. Quote Link to comment Share on other sites More sharing options...
marklarah Posted June 14, 2008 Share Posted June 14, 2008 Hang on, Im trying to work out what you want here....if the price of drugs is 10000, then you want something else to be 20% of 200? Can you please explain a little better? Quote Link to comment Share on other sites More sharing options...
grlayouts Posted June 14, 2008 Author Share Posted June 14, 2008 $q2 = mysql_fetch_row(mysql_query("SELECT SUM(drugs) FROM players;")); // GET THE AMMOUNT OF DRUGS function price ($q) { if ($q > 1000000) return 25; return ceil($q * -275 / 1000000) + 300; // if there more than 1000000 drugs do equasion. to get the price. } what i want instead of a price equasion is a percentage. ie $maxprice=200 equasion result = 15% so i would get 15% of 200 does that make sense? Quote Link to comment Share on other sites More sharing options...
marklarah Posted June 14, 2008 Share Posted June 14, 2008 So you want a function to work out a percentage? Simple. <? function jeff($perc, $num){ $perc = $perc/100; return $perc*$num; } echo jeff('15','100'); ?> (obviously adapt for your script) Quote Link to comment Share on other sites More sharing options...
grlayouts Posted June 14, 2008 Author Share Posted June 14, 2008 cant get what i want gonna start again 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.