php-windows | 2003032
Date: 03/25/03
- Next message: Rich Gray: "RE: [PHP-WIN] Simple Addition issue"
- Previous message: Luis Ferro: "Re: [PHP-WIN] installing Curl"
- Next in thread: Rich Gray: "RE: [PHP-WIN] Simple Addition issue"
- Reply: Rich Gray: "RE: [PHP-WIN] Simple Addition issue"
- Reply: Svensson, B.A.T. (HKG): "RE: [PHP-WIN] Simple Addition issue"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
I have a very dumb question that I'm puzzled with. I am creating a script that is returning tow values from a DB...The values will either be a number or the word resident so i'm checking for that first...if they are indeed numbers they need to be added together storing the sum in a variable which will give the total later in the script. For some reason I keep getting back a very incorrect value when using the script below:
$total_state_income = 0;
$row['CA_state_source_income'] = "14,133";
$row['GA_state_source_income'] = "Resident";
$row['IL_state_source_income'] = "10,556";
if(!strchr($row['CA_state_source_income'],"Resident"))
{
$total_state_income = $total_state_income + (int)$row['CA_state_source_income'];
}
if(!strchr($row['GA_state_source_income'],"Resident"))
{
$total_state_income = $total_state_income + (int)$row['GA_state_source_income'];
}
if(!strchr($row['IL_state_source_income'],"Resident"))
{
$total_state_income = $total_state_income + (int)$row['IL_state_source_income'];
}
When I check the value of $total_state_income it equals 24 not the expected 24,689.
The datatype of the values returned from SQL Server are Varchar so I tried typecasting the values to integers before adding them to the running total.
What am I doing wrong??
Thanks in advance for your help,
Ron
-- PHP Windows Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
- Next message: Rich Gray: "RE: [PHP-WIN] Simple Addition issue"
- Previous message: Luis Ferro: "Re: [PHP-WIN] installing Curl"
- Next in thread: Rich Gray: "RE: [PHP-WIN] Simple Addition issue"
- Reply: Rich Gray: "RE: [PHP-WIN] Simple Addition issue"
- Reply: Svensson, B.A.T. (HKG): "RE: [PHP-WIN] Simple Addition issue"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]

