$MR = $mt->query('select dated, time1 from det where cus="name 10" and dated between "10-06-2017" and "20-06-2017" order by dated asc');
$MR -> execute();
$result = $MR -> fetchAll();
$i=1;
if ($i%2) {
echo "<tr>";
echo "<td style='width:20%'>";
echo $i;
echo "</td>";
echo "<td style='width:20%'>";
echo $row['dated'];
echo "</td>";
echo "<td></td>";
echo "<td style='width:20%'>";
echo $row['time1'];
echo "</td>";
echo "</tr>";
} else {
echo "<tr>";
echo "<td style='width:20%'>";
echo $i;
echo "</td>";
echo "<td style='width:20%'>";
echo $row['dated'];
echo "</td>";
echo "<td style='width:20%'>";
echo $row['time1'];
echo "</td>";
echo "<td></td>";
echo "</tr>";
}
$i++;
}
我使用PDO做了一个fetchAll(),我的表在执行$ i%2之后看起来如下,其中$ i是计数器。
+---------+----------+-------------+------------+
| no | date | time 1 | time 2 |
+---------+----------+-------------+------------+
+---------+----------+-------------+------------+
| 1 |12-06-2017| 05:00 | |
+---------+----------+-------------+------------+
+---------+----------+-------------+------------+
| |12-06-2017| | 11:35 |
+---------+----------+-------------+------------+
+---------+----------+-------------+------------+
| 3 |13-06-2017| 04:4 | |
+---------+----------+-------------+------------+
+---------+----------+-------------+------------+
| |13-06-2017| | 13:25 |
+---------+----------+-------------+------------+
如何在 05:00 附近获得值 11:35 ,对于其他行也是如此。有超过100行。我可以显示time1的下一条记录吗?
分页不是我要找的东西。
[UPDATE]
预期输出
+---------+----------+-------------+------------+
| no | date | time 1 | time 2 |
+---------+----------+-------------+------------+
+---------+----------+-------------+------------+
| 1 |12-06-2017| 05:00 | 11:35 |
+---------+----------+-------------+------------+
+---------+----------+-------------+------------+
| 2 |13-06-2017| 04:4 | 13:25 |
+---------+----------+-------------+------------+
答案 0 :(得分:1)
试试这个
select dated,
Group_concat( time1 separator ',') as time1
from det
where
cus="name 10" and
dated between "10-06-2017" and "20-06-2017"
group by dated
order by dated asc
它将以“
”的形式发出dated | time1
12-06-2017 | 05:00,11:35
修改: - 强>
使用此代码创建表行
$times=explode(',', $row['time1']);
$time1=(isset($times[0]))?$times[0]:'';
$time2=(isset($times[1]))?$times[1]:'';
echo "<tr>";
echo "<td style='width:20%'>";
echo $i;
echo "</td>";
echo "<td style='width:20%'>";
echo $row['dated'];
echo "</td>";
echo "<td></td>";
echo "<td style='width:20%'>";
echo $row['time1'];
echo "</td>";