我将所有已存档的条目显示为这样,
2015条目
2004条目
现在我陷入困境,我一直试图通过选择特定的月份和年份来弄清楚如何显示已存档的条目。假设我想在2015年11月查看我的所有参赛作品,那么我在地址栏上的链接看起来就像......
?一年Display.php的= 2015&安培; MONTHNAME =十一月
执行代码时,条目显示为空白。到目前为止,我的代码看起来像这样。我还使用日期时间类型作为我的日期字段。感谢帮助。
$year = strip_tags(trim($_GET['year']));
$monthname = strip_tags(trim($_GET['monthname']));
$q = "select * from blog where year(date)='$year' and monthname(date) ='$monthname' order by date desc ";
$result= mysql_query($q, $connection) or die
("Could not execute query : $q." . mysql_error());
// dynamic navigation variables
$rows_per_page=1; // adjust the number here to display number of entries per page
$total_records=mysql_num_rows($result);
$pages = ceil($total_records / $rows_per_page);
$screen = $_GET["screen"];
if (!isset($screen))
$screen=0;
$start = $screen * $rows_per_page;
$q .= "LIMIT $start, $rows_per_page";
$result= mysql_query($q, $connection) or die
("Could not execute query : $q." . mysql_error());
while ($row=mysql_fetch_array($result))
{
$id=$row["id"];
$name=$row["name"];
$email=$row["email"];
$entry=$row["entry"];
$date=$row["date"];
$icon=$row["icon"];
$title=$row["title"];
?>
<table width="80%" border="0" cellspacing="1" cellpadding="0">
<tr>
<td><?php echo "$title"; ?></td>
</tr>
<tr>
<td>
<p><img src="<?php echo "$icon"; ?>" alt="icon" align="left"><?php echo "$entry"; ?></p>
<p>Posted by <a href="mailto:<?php echo "$email"; ?>"><?php echo "$name"; ?> on <?php echo "$date"; ?>.</p>
</td>
</tr>
</table>
<div align="center">
<?php
} #end of while
// Display dynamic navigation here
// create the dynamic links
if ($screen > 0) {
$j = $screen - 1;
$url = "display.php?year=$year&monthname=$monthname&screen=$j";
echo "<a href=\"$url\">Prev</a>";
}
// page numbering links now
for ($i = 0; $i < $pages; $i++) {
$url = "display.php?year=$year&monthname=$monthname&screen=" . $i;
$j = $i + 1;
echo " | <a href=\"$url\">$j</a> | ";
}
if ($screen < $pages-1) {
$j = $screen + 1;
$url = "display.php?year=$year&monthname=$monthname&screen=$j";
echo "<a href=\"$url\">Next</a>";
}
?>
</div>
答案 0 :(得分:0)
我忘记将monthname
放在我的地址栏上,并意外地将其保留为display.php?year=2015&month=November
无需修改代码。