Reputation: 53
Since I'm starting to get mysql to mysqli I've a some problems.
I've a page for exampe category.php?nameID=premium&id=12
This is a valid page with information, so when I go to for example: category.php?nameID=premium&id=1200
This page doesn't exist so I need to receive an error with This page doesn\'t exists!
$naamID = $db->real_escape_string(trim($_GET['nameID']));
$id = $db->real_escape_string(trim($_GET['id']));
$idnext = $id + 1;
$goo = $db->query("SELECT * FROM category INNER JOIN post ON category.name = post.cat WHERE post.cat = '" .$naamID. "' AND post.id = $id") or die($db->error);
//$gnn = $db->query("SELECT * FROM post WHERE id= $id ") or die(mysql_error());
//$gnnn = $gnn->fetch_assoc;
if($gooo = $goo->fetch_object());
if ($gooo === FALSE)
{
echo '<p>This post doesnot exist!</p>';
}
Upvotes: 0
Views: 37
Reputation: 933
You can use num_rows
to count rows in your query. If it is 0, there are no results and post does not exist.
if($goo->num_rows==0){
echo '<p>This post does not exist!</p>';
} else {
if($gooo = $goo->fetch_object()){
//exists
}
}
Upvotes: 1