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
https://forums.phpfreaks.com/topic/34776-updating-php/
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
https://forums.phpfreaks.com/topic/34776-updating-php/#findComment-163918
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
https://forums.phpfreaks.com/topic/34776-updating-php/#findComment-163936
Share on other sites

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.
Link to comment
https://forums.phpfreaks.com/topic/34776-updating-php/#findComment-163937
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
https://forums.phpfreaks.com/topic/34776-updating-php/#findComment-163944
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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