我正在制作一个博客,我需要一个博客存档。这是代码。
<dl class="accordion">
<?php
$showyear=mysql_query("SELECT `year` FROM `blogpost`");
while($farooq=mysql_fetch_array($showyear))
{
$year=$farooq['year'];
$_SESSION['blogarchive'][]=$year;
}
$blogarchive=$_SESSION['blogarchive'];
foreach($_SESSION['blogarchive'] as $year)
{
$showtitle=mysql_query("SELECT * FROM `blogpost` WHERE `year`='$year'");
while($umar=mysql_fetch_array($showtitle))
{
?>
<dt><a href=""><?php echo $year;?></a></dt>
<dd><a href="blogdetail.php?id=<?php echo $umar['post-id'];?>&action=profileblog"><?php echo $umar['title'];?></a></dd>
<?php
}
}
?>
</dl>
它的输出是
2011
2012
2013
2013
2013
haider
2013
2013
2013
2013
2013
2013
我想在一个像这样的
中显示所有2013年的帖子2013(9) 标题 标题
所以我怎么能这样做..
答案 0 :(得分:2)
这将显示输出为2013(9) -
<?php
$showtitle=mysql_query("SELECT DISTINCT * FROM `blogpost` WHERE `year`='$year'");
while($umar=mysql_fetch_array($showtitle))
{
?>
<dt><a href=""><?php echo $year;?></a></dt>
<dd><a href="blogdetail.php?id=<?php echo $umar[`year`];?>&action=profileblog"><?php echo $umar['title']."(".mysql_query("SELECT COUNT(*) FROM `blogspot` WHERE `post-id`=".$umar['post-id'].")";?></a></dd>
<?php
}
?>