Code:
$query = $db->query("SELECT day FROM impressions WHERE pub_id = '$pub_id' AND pub_tag = '$pub_tag' AND month = '$month' AND valid = '1' GROUP BY day ASC");
$stat_rev = $query->num_rows;
if($stat_rev > 0) {
while($revenue = $query->fetch_array())
{
$revenues[] = $revenue;
}
foreach($revenues as $revenue)
{
echo $rev_day = $revenue['day'].':';
$queryi = $db->query("SELECT revenue FROM impressions WHERE pub_id = '$pub_id' AND pub_tag = '$pub_tag' AND month = '$month' AND day = '$rev_day' AND valid = '1'");
while($rev = $queryi->fetch_array())
{
$revs[] = $rev;
}
foreach($revs as $rev)
{
//$total_rev = $total_rev + $rev['revenue'];
echo $rev['revenue'].',';
}
$queryi->close();
echo ' - ';
//echo '[\''.$revenue['day'].'\', '.$total_rev.'],';
$total_rev = 0;
}
}
Output:
28:0.001,0.001,0.006, - 29:0.001,0.001,0.006,0.006,0.001, -
Database:
28: 0.001
28: 0.001
28: 0.006
29: 0.006
29: 0.001
During the first loop run at which day is 28 the loop show 0.001, 0.001, 0.006.
Now at second loop run at which day is 29 the loop show 0.001, 0.001, 0.006, 0.006, 0.001.
The second loop is showing first loop values I have tried but cant fix it I want to show the values like 28: 0.001, 0.001, 0.006 and 29: 0.006, 0.001.
Thanks.
Before your while loop, you need to reset
$revs, otherwise you’re just appending more to the values that are already in it.Adding something like
$revs = array( );just inside the foreach should do the trick.