我的PHP中有一个查询,我正在搜索字符串:
select * from feed1 where PNAME like '%clothes%' limit 5;
我还想得到像我一样使用单独搜索查询的布料PNAME的数量:
$qry=mysqli_query(select * from feed1 where PNAME like '%clothes%');
$rows=mysqli_num_rows($qry);
行查询花费了太多时间来加载页面。有什么方法可以从一个查询中获得总行数和最多5个产品的限制吗?因此,加载时间将减少。
+-------+------------+----------+--------------+-------------+-----------+------
-------+----------+--------+------+------------+---------+---------------+
| Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardi
nality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |
+-------+------------+----------+--------------+-------------+-----------+------
-------+----------+--------+------+------------+---------+---------------+
| xml | 0 | PRIMARY | 1 | BOSID | A |
7233 | NULL | NULL | | BTREE | | |
+-------+------------+----------+--------------+-------------+-----------+------
-------+----------+--------+------+------------+---------+---------------+
1 row in set (0.00 sec)
答案 0 :(得分:0)
您无法通过一个查询执行此操作,但为了获取计数,请使用COUNT(*)
而不是获取所有数据。
要计算:
select count(*) from feed1 where PNAME like '%clothes%'
然后获得第5名:
select * from feed1 where PNAME like '%clothes%' limit 5
至少应该有两个分页查询。