num_rows is 0 when it should be >0 for php mysqli code
- by jpporterVA
My num_rows is coming back as 0, and I've tried calling it several ways, but I'm stuck. Here is my code:
$conn = new mysqli($dbserver, "dbuser", "dbpass", $dbname);
// get the data
$sql = 'SELECT AT.activityName, AT.createdOn
FROM userActivity UA, users U, activityType AT
WHERE U.userId = UA.userId
and AT.activityType = UA.activityType
and U.username = ?
order by AT.createdOn';
$stmt = $conn->stmt_init();
$stmt->prepare($sql);
$stmt->bind_param('s', $requestedUsername);
$stmt->bind_result($activityName, $createdOn);
$stmt->execute();
// display the data
$numrows = $stmt->num_rows;
$result=array("user activity report for: " . $requestedUsername . " with " . $numrows . " rows:");
$result[]="Created On --- Activity Name";
while ($stmt->fetch())
{
$msg = " " . $createdOn . " --- " . $activityName . " ";
$result[] = $msg;
}
$stmt->close();
There are multiple rows found, and the fetch loop process them just fine. Any suggestions on what will enable me to get the number of rows returned in the query?
Suggestions are much appreciated. Thanks in advance.