grlayouts Posted January 18, 2007 Share Posted January 18, 2007 ok i have a game with a factory payout, every hour it should see how many factories a player has and time them the random ammount and payout that ammount of drugs and counter bills.however it is updating everyone even the ones that have no factories with money and drugs, instead of only the ones with?[code]<?phpinclude("config.php");$stat = mysql_fetch_array(mysql_query("select * from players"));if (empty ($stat[id])) { print "Invalid login."; exit;}$userinfo = mysql_query("SELECT * FROM players where id=$stat[id]");$info = mysql_fetch_array($userinfo);error_reporting(E_ALL) ; ini_set("display_errors","1");$random1 = rand(10,15);$random2 = rand(30,50);$gain = $info['drugfact'] * $random1;$gain2 = $info['counterfact'] * $random2; mysql_query("update players set DDLQ=DDLQ+$gain");mysql_query("update players set credits=credits+$gain2");mysql_query("update players set drugpayout=$gain");mysql_query("update players set billpayout=$gain2");?>[/code] Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted January 18, 2007 Share Posted January 18, 2007 First of all, why not just use one UPDATE query? To update a specific thing you must set a condition, and you don't have any. Try this code:[code]<?phpinclude("config.php");$stat = mysql_fetch_array(mysql_query("select * from players"));if (empty ($stat[id])) { print "Invalid login."; exit;}$userinfo = mysql_query("SELECT * FROM players where id=$stat[id]");$info = mysql_fetch_array($userinfo);error_reporting(E_ALL) ; ini_set("display_errors","1");$random1 = rand(10,15);$random2 = rand(30,50);$gain = $info['drugfact'] * $random1;$gain2 = $info['counterfact'] * $random2; mysql_query("update players set DDLQ=DDLQ+$gain, credits=credits+$gain2, drugpayout='$gain', billpayout='$gain2' WHERE id=$stat[id]");?>[/code] Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 18, 2007 Share Posted January 18, 2007 The code says nothing about 'factories'. Are factories a seperate table? If so, you need to edit your query to get all players who have a record in the factory table.You haven't provided us enough info.Plus, poco is right, your updates are wrong ;) Quote Link to comment Share on other sites More sharing options...
Caesar Posted January 18, 2007 Share Posted January 18, 2007 I don't see anything in the code you're showing that checks to make sure a player/user has "factories". You need some conditional code that checks for it, either in the preceeding code or in the syntax of the query itself. Quote Link to comment Share on other sites More sharing options...
grlayouts Posted January 18, 2007 Author Share Posted January 18, 2007 [code]$gain = $info['drugfact'] * $random1;$gain2 = $info['counterfact'] * $random2; [/code]thats the factories? there in the same table under a stat. but even when players have no factories there still getting payouts. Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 18, 2007 Share Posted January 18, 2007 So like poco said, you need to fix your UPDATE. Quote Link to comment Share on other sites More sharing options...
grlayouts Posted January 18, 2007 Author Share Posted January 18, 2007 i tried his code and everyone is still updating? Quote Link to comment Share on other sites More sharing options...
Nhoj Posted January 18, 2007 Share Posted January 18, 2007 Give this a try.[code=php:0]<?include('config.php');error_reporting(E_ALL) ; ini_set('display_errors', 1);mysql_query('UPDATE `players` SET `DDLQ` = `DDLQ` + (`drugfact` * '.rand(10, 15).'), `credits` = `credits` + (`counterfact` * '.rand(30, 50).'), `drugpayout` = (`drugfact` * '.rand(10, 15).'), `billpayout` = (`counterfact` * '.rand(30, 50).')');?>[/code]That will update every single users information every time it is ran. It will only update users with factories... I'd recommend adding it to a 1 hour cron job. Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted January 18, 2007 Share Posted January 18, 2007 You need a query that selects exactly what you want...right now you have not explained good enough about the factories and tables for any of us to help you any more. Please explain in a bit more detail on what you are trying to accomplish. Quote Link to comment Share on other sites More sharing options...
grlayouts Posted January 18, 2007 Author Share Posted January 18, 2007 [quote author=Nhoj link=topic=123027.msg508068#msg508068 date=1169150708]Give this a try.[code=php:0]<?include('config.php');error_reporting(E_ALL) ; ini_set('display_errors', 1);mysql_query('UPDATE `players` SET `DDLQ` = `DDLQ` + (`drugfact` * '.rand(10, 15).'), `credits` = `credits` + (`counterfact` * '.rand(30, 50).'), `drugpayout` = (`drugfact` * '.rand(10, 15).'), `billpayout` = (`counterfact` * '.rand(30, 50).')');?>[/code]That will update every single users information every time it is ran. It will only update users with factories... I'd recommend adding it to a 1 hour cron job.[/quote]thank you so much its working perfectly.. :) 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.