我有一个博客设置,其中journal.php显示了数据库中博客的片段。它创建一个链接,以便在单击时应打开博客.php并显示完整的博客和评论部分。我不知道如何在日记中获取链接.php打开所选博客的 id,然后将其传递给博客.php并显示该博客。
期刊.php
<?php // retreive post
include('php/config.php');
include ('php/function.php');
dbConnect();
$blog_query = mysql_query(
'SELECT *
FROM Blog
ORDER BY DATE DESC');
function getIntro($str, $count = 200, $id=1) {
return preg_replace('/'s+?('S+)?$/', '', substr(nl2br($str), 0,
$count)) . '<a href="blog.php?page=' . $ID . '">Read more...</a>';
}
while($row = mysql_fetch_array($blog_query)):
$date = date_create($row['DATE']);
$str = $row['CONTENT'];
$ID = $row['ID'];
$new_string = getIntro($str);
?>
<div class="post">
<h2><?php echo $row['TITLE']?></h2>
<h3><?php echo date_format($date, 'l, F j, Y')?></h3>
<p><?php echo $new_string?></p>
</div>
</div>
<?php endwhile ?>
博客.php
<?php
include('php/config.php');
include ('php/function.php');
$_GET[$ID]; //Get ID from link in journal.php
dbConnect();
$data = mysql_query("SELECT * FROM Blog WHERE ID = '$ID'") or die(mysql_error());
$info = mysql_fetch_array( $data );
$BID = $info['ID'];
$date = date_create($info['DATE']);
?>
<div class="post">
<h2><?php echo $info['TITLE']?></h2>
<h3><?php echo date_format($date, 'l, F j, Y')?></h3>
<p><?php echo $info['CONTENT']?></p>
<h2>Comments.....</h2>
<div class="comment-block">
在博客中.php将$_GET[$ID];
更改为$ID = $_GET['page'];
另外,更改:
function getIntro($str, $count = 200, $id=1) {
自:
function getIntro($str, $count = 200, $ID=1) {
$ID = $_GET['page'];
因此,您可以在查询中使用$ID