如果该页面没有行,则显示错误。我会尝试解释我的问题:
我在我的网站上使用类别,例如'测试',我有一个与该类别相关的帖子,他的ID是1.所以链接将是
site.com/c/Test/1
效果很好,他显示来自ID=1
的信息。我还使用了INNER JOIN
所以当我去了类似的类别:site.com/c/Flow/1
时,他会显示一个像This post doesn't exist!
这样的错误因为ID=1
与名为Flow
的类别无关我试图解决这个问题,但没有任何结果。
<?php
// BEGIN OF SHOWING CONTENT PAGE
if (isset($_GET['id']))
{
$naamID = mysql_real_escape_string($_GET['nameID']);
$id = mysql_real_escape_string($_GET['id']);
$idnext = $id + 1;
$goo = mysql_query("SELECT * FROM category INNER JOIN post ON category.name = post.cat WHERE post.cat = '" .$naamID. "'") or die(mysql_error());
$gnn = mysql_query("SELECT * FROM post WHERE id= $id ") or die(mysql_error());
$gnnn = mysql_fetch_assoc($gnn);
$gooo = mysql_fetch_assoc($goo);
if($gnnn = mysql_fetch_array($gnn == ''))
{
echo 'This post doesnot exist!';
}
if($gooo['youtube'])
{
$fullurl1 = $gooo['youtube'];
$videoid1=substr($fullurl1,-11);
?>
<h1> <?php echo htmlspecialchars($gooo["title"]); ?> </h1><br />
<p>
<a href="/editpost.php?id=<?php echo htmlspecialchars($gooo['id']);?>"><i>Edit this post</i></a><br />
<iframe width="560" height="315" src="//www.youtube.com/embed/<?php echo htmlspecialchars($videoid1);?>" frameborder="0" allowfullscreen></iframe><br />
</p>
<?php }if($gooo['pic']){ ?>
<p>
<h1><?php echo htmlspecialchars($gooo["title"]); ?></h1><br />
<a href="/editpost.php?id=<?php echo htmlspecialchars($gooo['id']);?>"><i>Edit this post</i></a><br />
<img src="<?php echo htmlspecialchars($gooo["pic"]);?>" style="max-height: auto; max-width: 600px;"/><br>
</p>
<?php }
// END OF SHOWING CONTENT PAGE
} else {?>
答案 0 :(得分:0)
这应该是
if($gnnn = mysql_fetch_array($gnn == ''))
{
echo 'This post doesnot exist!';
}
像这样
if(mysql_num_rows($gnn) == 0)
{
echo 'This post doesnot exist!';
}