Jump to content

updating php


grlayouts

Recommended Posts

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]<?php
include("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]
Link to comment
Share on other sites

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]

<?php
include("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]
Link to comment
Share on other sites

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

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.
Link to comment
Share on other sites

[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.. :)
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

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

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.