How do I find out the number of rows return from a query when using stmt->prepare(); / stmt->execute();
In my example below, if i don’t get any results back, i would like to display an nice message to the user
Any ideas how to achieve this?
Thanks
EDITED:
as stated by @zerkms, there is a solution but, i was hoping for a solution that doesn’t buffer the entire result set in the statement handle…
….
$selected_disc = array(1=>'disc1', 2=>'disc2', 3=>'disc3');
// show tracks for each disc in album
$sql = 'SELECT track_id, name FROM album WHERE album_id = ?';
foreach ($selected_disc as $key => $disc) {
$stmt->prepare($sql);
$stmt->bind_param('i', $key);
$ok = $stmt->execute();
$stmt->bind_result($trackid, $name);
if( VALUES FOUND, SHOW !) {
while ($stmt->fetch()) {
echo $t_name;
}
} else {
echo 'Nothing to display... blablabla';
}
$stmt->free_result(); // free the database resources for other queries
}
...
There is a method for that: mysqli_stmt_num_rows() / mysqli_stmt::num_rows()