php - 执行mysqli语句后如何获取行数?
问题描述
我想将返回语句的行数存储在会话变量中,但我不知道如何。我正在尝试这样做,但它不起作用。
$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();
解决方案
我已经解决了这个问题,它的工作原理是这样的:
$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'];
推荐阅读
- spring-boot - MapStruct 不使用 Kotlin 和 Spring Boot 自动装配,使用 Gradle 构建
- angular - 如何使用 *ngFor 在同一个对象上迭代两次?
- r - R 中 exp(mean(log(murders$population))) 的 tidyverse 代码等效
- c++ - 在 C++ 内联汇编中定义变量
- python - Pandas 从多个名称元组列表中创建数据帧,但具有单独的成员
- r - 根据跨两个数据框的多列中的条件删除重复项
- javascript - 什么时候需要 Function 关键字?
- machine-learning - 预测后的pyspark ml模型图id列
- c# - 尝试将 C# 数组发送到 Python 并将其作为列表读取
- intellij-idea - 无法在 intelliJ 中运行简单的黄瓜功能文件