filling empty results with 0. Difficult php loops for getting db data

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

 



Hi there,

I have a problem where I can't get  further alone. In order to populate a
chart with 2 lines of data, I am pulling
out of a MySQL DB the data for graph 2.

Problem is, if graph 2 has viewer values than graph 1 this graph is not same
length. Lets say we are filling data for
month of April. There is not data for every day, so data for this empty day
should be the value of the previous day.
Sounds simple, right? But a hard nut for me ;-(

Maybe somone can give me a hand and lead me to the right way?

Thanx for any help.

Merlin

Here is the code I wrote:

 $i = 0;

 ###########
 # get data out of rows
 while($row = db_get_row($result)){
  $saved = false; // ini

  # run through all rows

   # only fill the value if data for this month /day
   echo $i.' X: '.$row->x_scale.' Xold: '.$chart[x_scale][$i].'<br>';
   if ($row->x_scale == $chart[x_scale][$i]){
    $saved = true;
    $i++;
    $all_members     = $all_members + $row->c;
    $chart[members_growth][]  = $all_members;
   echo 'value!  '.$all_members.'<br>';
   }


   # now new data growth
   if (!$saved){
    $i++;
    for ($z=$i; $z < count($chart[x_scale]);$z++){
     # save value from previous row if exists
     if ($all_members){
      $chart[members_growth][]  = $all_members;
   echo 'value saved!  '.$all_members.'<br>';
 #     echo $i.' N '.$row->x_scale.' '.$chart[x_scale][$i].'<br>';
     }
     else{
      $chart[members_growth][]  = '0';
   echo 'value!  0<br>';
 #     echo $i.' N0 '.$row->x_scale.' '.$chart[x_scale][$i].'<br>';
     }
    #echo $i.' s '.$row->x_scale.' '.$row->c.'<br>';
    }
   }
  echo '<br>NEXT row!<p>';
 }
 #############



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