问题是我得到一个奇怪的公告,而不是2个正常的公告(如在我的数据库中)。
现在的样子(截图):
https://prnt.sc/q5q8ju
码:
<?PHP $query = "SELECT * FROM `thbs_announcements` ORDER BY `anno_date` DESC";
$result1 = mysqli_query($db, $query);
$anno = mysqli_fetch_array($result1, MYSQLI_ASSOC);
if(mysqli_num_rows($result1) > 0)
{
while($anno = $result1->fetch_assoc());
{
if($anno['anno_important'] == 1)
{
?><div class="card"><h2 style="margin-bottom: 5px;"><?php echo $anno['anno_text'];?> <span class="badge badge-danger">IMPORTANT</span></h2></div><?php
}
if($anno['anno_important'] != 1)
{
$today = date("Y-m-d");
$dateDiffa = dateDiffInDays($today, $anno['anno_date']);
if($dateDiffa < 7 || $dateDiffa > -7)
{
?><div class="card"><h2 style="margin-bottom: 5px;"><?php echo $anno['anno_text'];?> <span class="badge badge-primary">NEW</span></h2></div><?php
}
else
{
?><div class="card"><h2 style="margin-bottom: 5px;"><?php echo $anno['anno_text'];?></h2></div><?php
}
}
}
}
else
{
?><div class="card"><h2 style="margin-bottom: 5px;">No announcements here.</h2></div><?php
}
?>
最佳答案
我希望这会起作用
<?PHP $query = "SELECT * FROM `thbs_announcements` ORDER BY `anno_date` DESC";
$result1 = mysqli_query($db, $query);
if(mysqli_num_rows($result1) > 0)
{
while($anno = mysqli_fetch_assoc($result1))
{
if($anno['anno_important'] == 1)
{
?><div class="card"><h2 style="margin-bottom: 5px;"><?php echo $anno['anno_text'];?> <span class="badge badge-danger">IMPORTANT</span></h2></div><?php
}
if($anno['anno_important'] != 1)
{
$today = date("Y-m-d");
$dateDiffa = dateDiffInDays($today, $anno['anno_date']);
if($dateDiffa < 7 || $dateDiffa > -7)
{
?><div class="card"><h2 style="margin-bottom: 5px;"><?php echo $anno['anno_text'];?> <span class="badge badge-primary">NEW</span></h2></div><?php
}
else
{
?><div class="card"><h2 style="margin-bottom: 5px;"><?php echo $anno['anno_text'];?></h2></div><?php
}
}
}
}
else
{
?><div class="card"><h2 style="margin-bottom: 5px;">No announcements here.</h2></div><?php
}
?>