You are here: noob question - integer output format, use of SUM in MySql « PHP Programming Language « IT news, forums, messages
noob question - integer output format, use of SUM in MySql

Posted by hph on 04/25/06 03:22

A bunch of small things are frustrating me in trying to do some simple
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
'%FF%'";
$result=mysql_query($dataquery);
$rowdata=mysql_fetch_row($result);
$datatotal=$rowdata[0];

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,
is 300.

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация