Jump to content

[SOLVED] Select from where money is more than 9mill????


burtybob

Recommended Posts

$num=mysql_query("SELECT * FROM members") or die (mysql_error());
$num=mysql_num_rows($num) or die (mysql_error());
$useridabc=0;
while ($num>$useridabc) {
$money="90,000,000";
$sql=mysql_query("SELECT * FROM members WHERE `userid`='$useridabc' AND `money`>'$money'") or die (mysql_error());
$sql=mysql_fetch_array($sql) or die(mysql_error());
$moneyaftertax=$sql[money];
$moneyaftertax=($moneyaftertax*0.99);
$sql2=mysql_query("UPDATE members SET `money`='$moneyaftertax' WHERE `userid`='$useridabc'");
$useridabc++;

 

Ok as far as i got is it either takes ALL the money or else it does the *0.99 all the time for all users even if they have less than 9mill.

I know that the $money is currently set to 90mill this is because i was testing to see if that made any difference however it did not i have tried all that i can think if so now i have come to the best place for php help :)

Thanks in advance burtybob  ;D

i might be wrong, but try removing the commas (and your quotes?) in your $money = "90,000,000"; line - only actual digits and a decimal point/negative - are valid in a number when used in this context, else it's classed as a string.

 

you can use money_format() or similar to display the number to the user "properly" on the page, but for the sake of comparisons, etc - a string wont work.

ok i tried that but that didnt work and it just brought up a blank page (errors are on) and when i went back to the with quotes and commas blank page??? still no idea as have tried it on localhost to the same problem as well as my webhost :(

dunno about the money thing... I'm just trying to grip the database pull logic here.

 

So you select ALL members, and figure out how many that is. Then, starting at 0, you move through each account's ID to the maximum account ID number. For each ID, you ask for a new set of data using ID tied to money > $money. This seems like such overkill... would this not do the same thing?

 

$money = '90000000';
$sql = "SELECT `userid`, `money` FROM `members`
        WHERE `money` > '$money'";
if ( !$result = mysql_query($sql) ) {
    die('Database error: ' . mysql_error());
}
WHILE ( $row = mysql_fetch_assoc($result) ) {
    $moneyaftertax = intval($row['money']);
    $moneyaftertax = $moneyaftertax*.99;
    $sql2 = "UPDATE `members`
             SET `money` = '$moneyaftertax'
             WHERE `userid` = '{$row['userid']}'
    if ( !$result2 = mysql_query($sql2) ) {
        die('Database error: ' . mysql_error());
    }
}

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.