php - MySQL查询结果后如何显示下5条记录或行?
问题描述
我在表中有一个包含类似单词的列
- 抗菌
- 花生
- 弃权
- 疏离
- 阿布内特
- 阿普蒂斯顿
因此,当我查询单词“Abacterial”时,它会显示“Abacterial”的结果,但我还想显示接下来的 5 个单词。
我使用这个 MySQL 查询代码:mysqli_query($conn, "SELECT * FROM medi_words WHERE word LIKE '%$query%'");
解决方案
$query = "SELECT * FROM medi_words WHERE word LIKE '%$query%' LIMIT 5";
if ($result = mysqli_query($link, $query)) {
/* fetch associative array */
while ($row = mysqli_fetch_assoc($result)) {
printf ("%s (%s)\n", $row["word"]);
}
/* free result set */
mysqli_free_result($result);
}
推荐阅读
- vue.js - 在 vuejs 中上传时为空路径
- python - 如何连接图表的两个部分?在蟒蛇
- python-3.x - libpcap 安装在 macOS 上但不受支持
- azure - Azure SignalR“资源处于故障状态” - 如何诊断问题?
- java - Closeable接口的close()方法是否在签名中有异常
- blazor - Mudblazor - 样式组件:例如:表格
- java - 检查更改日志和数据库是否相等
- hadoop - 使用 hive 3 时无法从空字符串创建路径
- c++ - 为什么指向字符串的指针给了我空白输出
- java - 如何通过 cgo/JNA 将 Java 字符串数组 []String 传递给 Go