filling empty results with 0. Difficult php loops for getting db data
| From: | Merlin | Date: | Sun, 11 May 2003 10:42:16 +0000 |
| Subject: | filling empty results with 0. Difficult php loops for getting db data | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-27647@lists.php.net to get a copy of this message | ||
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>';
}
#############