我想在会话变量中存储返回语句的行数,但是我不知道如何。我正在尝试这样做,但是没有用。
$stmt = $con->prepare("SELECT model, type, color FROM item WHERE model LIKE '%$type%'");
$stmt->execute();
$_SESSION['numRows'] = $stmt->num_rows;
echo $_SESSION['numRows'];
$result = $stmt->get_result();
$_SESSION['itemsInfo'] = $result->fetch_all();
答案 0 :(得分:-1)
我已经解决了问题,它的工作原理如下:
$stmt = $con->prepare("SELECT model, type, color FROM item WHERE model LIKE '%$type%'");
$stmt->execute();
$result = $stmt->get_result();
$_SESSION['itemsInfo'] = $result->fetch_all();
$_SESSION['numRows'] = count($_SESSION['itemsInfo']);
echo $_SESSION['numRows'];