Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Posted on
April 25, 2006, 12:22 am
rate this thread
stuff with MySQL and php.
For example, I have am trying to sum the data in a particular field,
then output the result.
Here is the sequence I'm using in php to do so:
$dataquery="SELECT SUM(".$current_year.") FROM Donors WHERE Source LIKE
Donors is of course the name of the table, $current_year is a variable
that is correctly 2006 (I've echoed it to make sure), and I'm looking
for the total of data in field 2006 where the associated field Source
contains the letters FF somewhere.
However, the result is displaying as 62186 when in fact it's 300.
Even if I use phpmyadmin and enter the query directly [SELECT SUM(2006)
FROM Donors WHERE Source LIKE '%FF%'], the result comes back
incorrectly, again 62186 instead of the expected 300.
So what am I doing wrong? The field 2006, which can hold values between
0 and 999,999, is defined as an INT 6. If I do the MySQL command
[SELECT FROM Donors WHERE Source LIKE '%FF%'] I do see just a small
number of rows, and the total in the fields 2006, computed in my head,
Re: noob question - integer output format, use of SUM in MySql
Your query is:
SELECT SUM(2006) FROM Donors WHERE Source LIKE '%FF%';
In this context, 2006 is a *NUMBER*. `2006` is a field.
I advise not naming fields so they look like numbers.
This is 31 * 2006.
You should not be expecting 300 here.
Gordon L. Burditt
- » pg_connect(): Cannot create new link. Too many open links (0)
- — Previous thread in » PHP Scripting Forum