几句话之后,我点了一个阅读更多按钮,当我点击阅读更多它显示完整的消息,它是好的,但它显示我的所有帖子的完整消息。我需要个别帖子的完整信息,请你告诉我我的代码中有什么问题:
这是我在不同文件中使用的函数,名称:“func.php”
<?php
function truncate($mytext,$link,$var,$id) {
//Number of characters to show
$chars = 200;
$mytext = substr($mytext,0,$chars);
$mytext = substr($mytext,0,strrpos($mytext,' '));
$mytext = $mytext." <a href='$link?$var=$id'>read more...</a>";
return $mytext;
}
?>
<?php
include "db/db.php";
$upload_path = "secure/content/blogpostimg";
$sql= mysql_query("SELECT * FROM blog_post ORDER BY post_id DESC");
while ($rel = mysql_fetch_assoc($sql))
{
$id = $rel['post_id'];
$sub = $rel['subject'];
$imgname = $rel['img_name'];
$img = $rel ['image'];
$msg = $rel['message'];
$date = $rel['date'];
$poster = $rel['poster'];
$cat_name = $rel['cat_name'];
echo "<h1>". "$sub" ."</h1>". "<br/>";
echo '<img src="' . $upload_path . '/' . $imgname . '" width="200" /> ';
include_once("func.php");
echo truncate($rel['message'],"index.php","post_id",$rel['post_id']);
}
?>
答案 0 :(得分:0)
您需要检查index.php
以查看$_GET['post_id']
是否已设置,如果是,则显示不同的MySQL选择
if (isset($_GET['post_id']) && $_GET['post_id'] != '') {
$p_id = (int) $_GET['post_id'];
$sql= mysql_query("SELECT * FROM blog_post WHERE post_id = '{$p_id}' ORDER BY post_id DESC");
} else {
$sql= mysql_query("SELECT * FROM blog_post ORDER BY post_id DESC");
}
// Your original code. Only at the end, if $p_id is set, display a full post view instead of the truncate() function