mysql表
--work table-- --crew table--
date | hours date | name
2013-02-03(Sun) 8 2013-02-03 john
2013-02-04(Mon) 7 2013-02-03 sam
2013-02-03 peter
2013-02-04 john
2013-02-04 sam
询问
SELECT hours, name, DAYNAME(work.date) day
FROM work
LEFT JOIN crew ON work.date = crew.date
WHERE WEEK(work.date) = 5
结果
hours name day
8 John Sunday
8 Sam Sunday
8 Peter Sunday
7 John Monday
7 Sam Monday
现在像这样在html中格式化,如何?
Name Sunday Monday Tuesday..(day name can be written in html)
John 8 7 ...
Sam 8 7 ...
Peter 8 - ...
伪代码
<?php foreach($result as $r): ?>
<tr>
<td>
<?php echo $r->name; ?>
</td>
<td>
<?php echo $r->hours on Monday; ?>
</td>
<td>
<?php echo $r->hours on Tuesday; ?>
</td>
<td>
<?php echo $r->hours on Wednesday; ?>
</td>
..
..
</tr>
<?php endforeach; ?>