【发布时间】:2017-03-07 06:44:42
【问题描述】:
我正在尝试在表格(图 1)上显示 7 个结果,我想将它们移动到正确的位置。
Mon = 1 ~ Sun = 7,正如我们在阵列上看到的那样,在没有价值的地方,我希望它是 0 美元。目前我不知道如何将它移动到桌子上的正确位置。
这是我的代码:
$w_rep = "SELECT
`totals`.`totals_weeknumb`,
`totals`.`totals_weekday`,
`totals`.`totals_of_day`
FROM `totals`
WHERE `totals`.`totals_has_users_id` = :fromID";
$w_rep_stmt = $DB->prepare($w_rep);
$w_rep_stmt->execute(array(':fromID' => $fromID));
$w_rep_stmt->setFetchMode(PDO::FETCH_ASSOC);
$totals_of_day = array();
foreach ($w_rep_stmt as $report) {
//$tdate = new DateTime($report['totals_date']);
//$totals_date = $tdate->format('d-m-Y');
$t_wnumber = (int)$report['totals_weeknumb'];
$t_wday = (int)$report['totals_weekday'];
$totals_of_day[$t_wnumber][$t_wday] = (float)$report['totals_of_day'];
//$sum_of_week[$t_wnumber] = array_sum(array_column($totals_of_day, ''));
} // close foreach
var_dump(array_keys($totals_of_day));
var_dump($totals_of_day);
foreach ($totals_of_day as $w_n => $y) {
?>
<tr>
<th><?php echo $w_n; ?></th>
<td><a href="#" title="Click for more details">More Details</a></td>
<?php
foreach ($y as $w_day => $saved) {
echo '<td>'. $curr.number_format($saved, 2) .'</td>';
} // close foreach
?>
<td><?php //echo $curr.$sum_of_week[]; ?></td>
</tr>
<?php
} // close 1st foreach
我尝试了很多选择:(
【问题讨论】:
-
所以您只是缺少 0$ 值?
-
是的,将结果移到正确的日期!
标签: php html arrays html-table