我的num_rows回來爲0,我試着用幾種方式調用它,但我卡住了。這裏是我的代碼:num_rows爲0時,它應該> 0爲PHP mysqli代碼
$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();
找到了多行,並且抓取循環處理它們就好了。有什麼建議可以讓我獲得查詢中返回的行數?
建議非常感謝。提前致謝。
完美。謝謝。 – jpporterVA 2012-04-13 23:51:19