代码:
$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;
}
}
输出:
28:0.001,0.001,0.006, - 29:0.001,0.001,0.006,0.006,0.001, -
数据库:
28: 0.001
28: 0.001
28: 0.006
29: 0.006
29: 0.001
在第一次循环运行期间,当天是 28,循环显示 0.001、0.001、0.006。现在在第 29 天第二次循环运行时,循环显示 0.001、0.001、0.006、0.006、0.001。第二个循环显示我尝试过但无法修复的第一个循环值我想显示诸如 28 之类的值:0.001、0.001、0.006 和 29:0.006、0.001。谢谢。