Professional Web Applications Themes

noob question - integer output format, use of SUM in MySql - MySQL

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 ...

  1. #1

    Default noob question - integer output format, use of SUM in MySql

    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.
    hph Guest

  2. #2

    Default Re: noob question - integer output format, use of SUM in MySql

    >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.
    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.
    >However, the result is displaying as 62186
    This is 31 * 2006.
    >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.
    You should not be expecting 300 here.
    >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.
    Gordon L. Burditt
    Gordon Burditt Guest

  3. #3

    Default Re: noob question - integer output format, use of SUM in MySql

    In article <124rg075197ln6ecorp.supernews.com>,
    [email]gordonb.gylhmburditt.org[/email] (Gordon Burditt) wrote:

    [snip]
    >
    > 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.
    Yes, this fixed the problem. I renamed field 2006 to Yr2006 and
    everything worked as I'd have expected. Thanks.
    hph Guest

Similar Threads

  1. How to format Integer to include comma
    By asdren_one in forum Coldfusion - Getting Started
    Replies: 4
    Last Post: March 9th, 10:58 AM
  2. sorry noob question
    By the rebel in forum Macromedia Director 3D
    Replies: 3
    Last Post: September 26th, 12:17 PM
  3. Stupid Noob Question
    By slowlrner in forum Macromedia Freehand
    Replies: 3
    Last Post: February 27th, 05:33 AM
  4. Noob question
    By drew146 webforumsuser@macromedia.com in forum Macromedia Fireworks
    Replies: 1
    Last Post: October 5th, 11:24 PM
  5. question from perl noob
    By boblehue in forum PERL Miscellaneous
    Replies: 9
    Last Post: August 1st, 09:59 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139