我的 num_rows 以 0 的形式返回,我尝试了几种方式调用它,但我被卡住了。这是我的代码:
$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();
找到了多行,提取循环处理它们就好了。关于什么可以让我获得查询中返回的行数的任何建议?
非常感谢您的建议。提前致谢。