我正在使用PHP和MySQL创建日历。
我已经使它工作,所以你可以删除,编辑和创建新的生日。
但现在我无法弄清楚如何使每个月只显示一次,并让那个月的其他日子在这个月的第一次出现之下。
有谁知道如何使这个工作?
<h1>Calendar</h1>
<ul>
<?php
$month = array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
foreach($birthdays as $Birthday){
?>
<h1><ul><?=$month[$Birthday["month"]-1];?></ul></h1>
<h2><ul><?=$Birthday["day"];?></ul></h2>
<a href="<?= URL?>birthday/edit/<?=$Birthday['id'];?>"><ul><?=$Birthday["person"];?> <a href="<?= URL?>birthday/delete/<?= $Birthday['id'] ?>" onclick= "return confirm ('Are you sure you want to delete this birthday??');">x</a></ul></a><br>
<?php }?>
<p><a href="create">Add</a></p>
答案 0 :(得分:0)
您可以将$month
写在临时变量中,并检查当前$month
是否不同。
$_month = null;
foreach($birthdays as $Birthday){
if($_month != $Birthday["month"]){
$_month = $Birthday["month"];
echo sprintf("<li><h1>%s</h1></li>", $month[$Birthday["month"]-1]);
}
// Other output
}