Display Message if num_rows = 0 in php from mysqli prepared-statement [duplicate]
I am having an issue trying to get the number of rows from a prepared statement query in php, my query looks as follows:
$DBH = getDBH();
$stmt = $DBH->prepare("SELECT info FROM list WHERE tag = ?");
$stmt->bind_param("s",$tag);
$stmt->execute();
$stmt->bind_result($information);
and i basically just want to say if there is no result returned display "no result returned" can anyone please help?
You need to use $statement->store_result()
first. Using your code:
$DBH = getDBH();
$stmt = $DBH->prepare("SELECT info FROM list WHERE tag = ?");
$stmt->bind_param("s",$tag);
$stmt->execute();
$stmt->store_result();
$num_rows = $stmt->num_rows;
$stmt->bind_result($information);
I don't recognize the class you are using, but generally I do this:
$sql = "SELECT * FROM dummy WHERE category=13";
$result = mysql_query($sql);
if(mysql_num_rows($result)>0) {
// execute for positive results
} else {
// execute for 0 rows returned.
}
$sql = "SELECT * FROM dummy WHERE category=13";
$result = mysqli_query($link, $sql);
$numrows=mysqli_num_rows($result)
if($numrows>0) {
// execute for positive results
} else {
// execute for 0 rows returned.
}
精彩评论