請檢查圖像,它將解釋視覺DATE重複,直到while循環讀取記錄
http://dubads.com/temp/Untitled-1.jpg
for ($index = 1; $index <= $numdays; $index++) {
$users =
"SELECT invoice_date, DAY(invoice_date) as invoiceday, " .
"sum(total_amount) as fullamount from invoices " .
"WHERE MONTH(invoice_date)='".$month."' AND YEAR(invoice_date)='".$year.
"' GROUP BY invoiceday";
$res = mysql_query($users);
$row = mysql_num_rows($res);
while ($fetch = mysql_fetch_array($res)) {
echo "<tr id='".(($j % 2 == 0) ? 'row3' : 'row4')."'>";
$explodedate = explode("-", $fetch['invoice_date']);
$days = $explodedate[2];
$month1 = $explodedate[1];
$year1 = $explodedate[0];
$dates = date("jS", strtotime($fetch['invoice_date']));
echo "<td style='text-align:left;padding-left:12px'>".$index.
"</td>";
if ($index == $dates) {
echo "<td style='text-align:right;padding-right:12px'>".
$fetch['fullamount']."</td>";
} else {
echo "<td style='text-align:right;padding-right:12px'>--</td>";
}
echo "</tr>";
}
}
$total =
"SELECT SUM(total_amount) as fulltotal from invoices where MONTH(invoice_date)='".
$month1."' AND YEAR(invoice_date)='".$year1."';";
$totres = mysql_query($total);
$totfetch = mysql_fetch_assoc($totres);
if ($totfetch['fulltotal'] == "") {
echo "<tr><td>NOTHING FOUND</td></tr>";
} else {
ECHO "<TR>";
echo "<td style='color:#BD0000;padding-left:12px;border:1px solid #ccc;width:20%;height:40px;text-align:left'>TOTAL AMOUNT </td>";
echo "<td style='color:#BD0000;border:1px solid #ccc;width:20%;height:40px;text-align:right;padding-right:12px'>".$totfetch['fulltotal']."</TD></TR>";
}
echo "</table>";
更多的解釋將是爲了即使有圖像!並且請通過刪除與問題無關的所有內容來縮短代碼。 – markus 2011-04-02 11:50:14
他需要計算sql調用中特定日期的所有值的總和。 – Hossein 2011-04-02 12:15:04
如果您看到圖像,則已經計算出總和。與查詢相關的金額和/或任何內容都沒有問題。正如我所說的問題是,這一天正在重複。發票的價值也放在正確的行(日期)中,唯一的是它不會輸出一個月。如果有多條記錄,則會重複該月份的日期,並且月份的重複次數與記錄的次數相同。 – khan 2011-04-02 12:21:44