After few word i put a read more button when i click read more it's show full message, it's Ok, but It's show all my post's full message. I need individual post's full message, Can you please tell me what is the wrong in my code bellow:
This is a function i used in my code in different file, name: "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']);
}
?>
You need to do a check on index.php
to see if the $_GET['post_id']
is set, and if so, display a different MySQL select
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