【发布时间】:2014-07-16 06:36:05
【问题描述】:
我的数据库中有 7 月 1 日、7 月 2 日、8 月 1 日、9 月 1 日、11 月 1 日、8 月 2 日的日期。我遍历日期,结果是这样。
如何使用 eloquent 获得 7 月 1 月的月份,即使它有同一个月份,结果会是这样?
<table>
<thead>
<tr>
<th>Test Type</th>
<?php
$types = Tblreporttype::all();
?>
@foreach($types as $type)
<?php
$dates = Tblreportdate::with('tblreporttype')
->groupBy('fDate')
->where('tblreporttype_id', '=', $type->id)
->get();
?>
@foreach($dates as $date)
<?php
$convert = $date->fDate;
$my_date = date('M/y', strtotime($convert));
?>
<th width="100">
<?php
if($my_date == $my_date) {
echo $my_date;
}
?>
</th>
@endforeach
@endforeach
</tr>
</thead>
<tbody>
<?php
$dates = Tblreportdate::with('tblreporttype')
->groupBy('fDate')
->get();
?>
<?php
$types = Tblreporttype::all();
?>
@foreach($types as $type)
<tr>
<td width="200">{{ $type->fType }}</td>
@foreach($dates as $date)
<?php
$convert = $date->fDate;
$my_date = date('d', strtotime($convert));
?>
<td width="100">
<?php
if($date->tblreporttype->id == $type->id) {
echo $my_date;
} else {
echo " ";
}
?>
</td>
@endforeach
</tr>
@endforeach
</tbody>
</table>
【问题讨论】:
-
您至少可以发布您当前的代码吗?
-
输出不同但思路还是一样
标签: php mysql date laravel eloquent