Jump to content

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


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());
    }
}

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.