我的SQL表中有以下数据:
id code day time year
1 PRC-001 0 t-1 2017
2 PRC-001 1 t-2 2017
3 PRC-002 0 t-3 2017
4 PRC-002 1 t-4 2017
5 PRC-003 0 t-5 2017
6 PRC-003 1 t-6 2017输出应如下所示:
Friday Saturday code
09:30-10:30 03:30-04:30 PRC-001
10:40-11:40 04:45-06:00 PRC-002
11:50-12:50 06:10-07:10 PRC-003 如何针对t-1=> 09:30-10:30,t-2=>03:30-04:30,day 0=>Friday,day 1=>Saturday设置该值。我已经为此编写了一个函数。但是不能获得值。下面是我的代码:
function getTime(){
$time = array(
t-1 => "09:30 A.M. - 10:30 A.M.",
t-2 => "10:40 A.M. - 11:40 A.M.",
t-3 => "11:50 A.M. - 12:50 P.M.",
t-4 => "03:30 P.M. - 04:30 P.M.",
t-5 => "04:45 P.M. - 06:00 P.M.",
t-6 => "06:10 P.M. - 07:10 P.M.",
);
return $time;
}
function getDay(){
$days = array(
0 => "Friday",
1 => "Saturday",
2 => "Sunday",
3 => "Tuesday",
4 => "Thursday",
);
return $days;
}
$rs = mysql_query("SELECT * FROM routine");
$results = [];
while ($row = mysql_fetch_assoc($rs)) {
$code = $row['code'];
if (!isset($results[$code])) {
$results[$code] = [
'day0' => '-',
'day1' => '-',
];
}
$results[$code]['day' . $row['day']] = $row['time'];
}
?>
<table>
<thead>
<tr id="grey">
<th rowspan="2">Day0</th>
<th rowspan="2">Day1(s)</th>
<th rowspan="2">code</th>
</tr>
</thead>
<tbody>
<?php foreach ($results as $code => $result) : ?>
<!--You shouldn't have multiple elements using the same ids-->
<tr>
<td id='clist'><?php echo $result['day0'] ?></td>
<td id='clist'><?php echo $result['day1'] ?></td>
<td id='clist'><?php echo $code ?></td>
</tr>
<?php endforeach ?>
</tbody>
https://stackoverflow.com/questions/41478261
复制相似问题