I am trying to have this script update for the users in the top 5, top 10, top 25, and top 50 winnings, but it is only paying out news and goldcoins to the top networth player. Can someone please fix this for me?
[php]$sql=“SELECT nickname, email, rank, uid, SUM(bank+cash) AS nw FROM user_characters WHERE rank!=‘Admin’ and rank!=‘Forum Mod’ and nickname!=‘Guest’ and rank!=‘Public Relations’ GROUP BY nickname ORDER BY nw DESC LIMIT 0,5;”;
$sql=mysql_query($sql);
if(@mysql_num_rows($sql)==0) {}
else {
while($temp=mysql_fetch_array($sql))
{
$sql = “UPDATE users_goldcoins SET goldcoins=goldcoins+200 WHERE uid=”.$temp[uid]."";
$sql = mysql_query($sql) or die(mysql_error());
$sql = “INSERT INTO news
(to
, news
, timestamp
) VALUES (’”.$temp[‘email’]."’, ‘
Congratulations. You Have Won 200 B.D(s) For Finishing Within The Top 5 Networth. ‘, ‘$time’)";
$sql = mysql_query($sql) or die(mysql_error());
}}
$sql=“SELECT nickname, email, rank, uid, SUM(bank+cash) AS nw FROM user_characters WHERE rank!=‘Admin’ and rank!=‘Forum Mod’ and nickname!=‘Guest’ and rank!=‘Public Relations’ GROUP BY nickname ORDER BY nw DESC LIMIT 0,10;”;
$sql=mysql_query($sql);
if(@mysql_num_rows($sql)==0) {}
else {
while($temp=mysql_fetch_array($sql))
{
$sql = “UPDATE users_goldcoins SET goldcoins=goldcoins+100 WHERE uid=”.$temp[uid]."";
$sql = mysql_query($sql) or die(mysql_error());
$sql = "INSERT INTO news
(to
, news
, timestamp
) VALUES (’".$temp[‘email’]."’, ‘
Congratulations. You Have Won 100 B.D(s) For Finishing Within The Top 10 Networth. ‘, ‘$time’)";
$sql = mysql_query($sql) or die(mysql_error());
}}
$sql=“SELECT nickname, email, rank, uid, SUM(bank+cash) AS nw FROM user_characters WHERE rank!=‘Admin’ and rank!=‘Forum Mod’ and nickname!=‘Guest’ and rank!=‘Public Relations’ GROUP BY nickname ORDER BY nw DESC LIMIT 0,25;”;
$sql=mysql_query($sql);
if(@mysql_num_rows($sql)==0) {}
else {
while($temp=mysql_fetch_array($sql))
{
$sql = “UPDATE users_goldcoins SET goldcoins=goldcoins+50 WHERE uid=”.$temp[uid]."";
$sql = mysql_query($sql) or die(mysql_error());
$sql = "INSERT INTO news
(to
, news
, timestamp
) VALUES (’".$temp[‘email’]."’, ‘
Congratulations. You Have Won 50 B.D(s) For Finishing Within The Top 25 Networth. ‘, ‘$time’)";
$sql = mysql_query($sql) or die(mysql_error());
}}
$sql=“SELECT nickname, email, rank, uid, SUM(bank+cash) AS nw FROM user_characters WHERE rank!=‘Admin’ and rank!=‘Forum Mod’ and nickname!=‘Guest’ and rank!=‘Public Relations’ GROUP BY nickname ORDER BY nw DESC LIMIT 0,50;”;
$sql=mysql_query($sql);
if(@mysql_num_rows($sql)==0) {}
else {
while($temp=mysql_fetch_array($sql))
{
$sql = “UPDATE users_goldcoins SET goldcoins=goldcoins+25 WHERE uid=”.$temp[uid]."";
$sql = mysql_query($sql) or die(mysql_error());
$sql = "INSERT INTO news
(to
, news
, timestamp
) VALUES (’".$temp[‘email’]."’, '
Congratulations. You Have Won 25 B.D(s) For Finishing Within The Top 50 Networth. ', ‘$time’)";
$sql = mysql_query($sql) or die(mysql_error());
}}[/php]
!= in mysql is <>. I see how you’re trying to do it, not all that efficient, but that’s for another thread and another time.
never suppress queries until you’re sure they’re working. Its only doing the first one because its first in the array. You need to move the selections into an array, then do your updates and inserts from that.
Below is just the first one[php]
$sql=mysql_query(“SELECT nickname, email, rank, uid, SUM(bank+cash) AS nw FROM user_characters WHERE rank <>‘Admin’ and rank <> ‘Forum Mod’ and nickname <> ‘Guest’ and rank <> ‘Public Relations’ GROUP BY nickname ORDER BY nw DESC LIMIT 0,5”);
if(mysql_num_rows($sql)==0) {
echo “Query Failed:”.mysql_error();
} else {
while($temp=mysql_fetch_array($sql)) {
$gc = $temp[‘goldcoins’]+200;
$win[] = array(‘gc’=>$gc, ‘uid’=>$temp[‘uid’], ‘email’=>$temp[‘email’]);
{
$time = time();
foreach($win as $key => $val) {
mysql_query(“UPDATE users_goldcoins SET goldcoins=$val[‘gc’] WHERE uid=’$val[uid]’”) or die(mysql_error());
mysql_query(“INSERT INTO news
(to
, news
, timestamp
) VALUES (’$val[email]’, '
Congratulations. You Have Won 200 B.D(s) For Finishing Within The Top 5 Networth. ', ‘$time’)”) or die(mysql_error());
}
}[/php]