Re: difficult count statement

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello John,

thanx for your instructions. I have tryed to understand this, but looks like
I have failed. The pice of code underneath is a creation of mine and should
do what you have explained. Does not though ;-( There is one error anywhere
inside the code and the longer I work on it, then more chaotic it looks
like. Don't know if you have the time to look on it? Can it be that hard?
Don't put to much time in it, but if you can see the problem let me know.
Your programming skills seem a lot better than mine.

Here is the code I wrote:

$start = 0;
while($row = db_get_row($result)){
     $saved = false; // ini
     for ($i=$start;$i <= count($chart[x_scale]);$i++){ // run through all
rows
         if ($row->x_scale == $chart[x_scale][$i]){ // only fill the value
if data for this month /day
             $saved = true;
             $start = (int)($row->x_scale);
             $all_members     = $all_members + $row->c;
             $chart[members_growth][]  = $all_members;
          }
          else{ // now new data growth
               if (!$saved){
                    if ($all_members){
                         $chart[members_growth][]  = $all_members;
                   }
                    else{
                        $chart[members_growth][]  = '0';
               }
           }
      }
};

Thanx, Merlin

----- Original Message -----
From: "John W. Holmes" <holmes072000@charter.net>
To: "'Merlin'" <news.groups@web.de>; <php-db@lists.php.net>
Sent: Monday, May 05, 2003 6:22 PM
Subject: RE:  difficult count statement


> > > SELECT     DATE_FORMAT( date_column, '%Y- %m- %d') AS mydate,
> > >                    COUNT(*) AS c
> > > FROM         table
> > > GROUP BY mydate
> >
> > This wokes. Thank you ignatius! I have worked on the charts and it
> helped
> > me
> > to get a lot further.
> > There is a point where I still have not found a good solution.
> >
> > Problem is, that there are some days where no data has changed (for
> > example
> > a day with no new registered members).
> > In this case the query should return '0'
> >
> > E.g.:
> > Jan    10
> > Feb   32
> > Mar   0
> > Apr   5
> >
> > At the moment I would not have march listed in my chart which causes
> > problems.
>
> I'd just handle the empty months in PHP.
>
> 1. Issue your query to retrieve the months you want, ordered by month
> ascending.
>
> 2. Retrieve first row containing month and count
>
> 3. Create a PHP loop that starts at the first month's timestamp until
> the last month.
>
> 4. Compare the month of the loop with the month retrieved from the
> database. If they match, output the number and fetch the next row. If
> they do not match, output zero, do not fetch another row and move on to
> the next month in your PHP loop.
>
> 5. Continue until done.
>
> This way you don't have to create and maintain a dummy database with
> months/dates in it and your query will be less complex.
>
> ---John W. Holmes...
>
> PHP Architect - A monthly magazine for PHP Professionals. Get your copy
> today. http://www.phparch.com/
>
>
>


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux