我的代码中没有问题。
我需要先$sql
运行才能获得$p_id
,但它会在第二位运行$sql
,这样我就无法获得$p_id = (int) $_GET['post_id'];
。
你能告诉我为什么吗?
<?php
error_reporting(E_ALL);
ini_set('display_errors',1);
include "db/db.php";
$upload_path = "secure/content/blogpostimg";
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'");
} else {
$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 substr($msg, 0, 200)."..." . "<a href=index.php?post_id= '$p_id'
target='_blank'>Read more</a>";
?>