php isset($ _ GET [' post_id'])问题

时间:2011-12-15 07:22:13

标签: php mysql

我的代码中没有问题。

我需要先$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>";
?>

1 个答案:

答案 0 :(得分:2)

如果您有兴趣,可以阅读这篇文章。它简单明了,非常适合理解isset和empty之间的差异:http://kunststube.net/isset/