sphinxql如何得到结果数及show meta的详细说明
mysql
select count() from main_index;
这个在这里却报语法错误。
第一种方法
查文档得
Aggregate functions (AVG(), MIN(), MAX(), SUM()) in column list clause are supported. Arguments to aggregate functions can be either plain attributes or arbitrary expressions. COUNT() is implicitly supported as using GROUP BY will add @count column to result set. Explicit support might be added in the future. COUNT(DISTINCT attr) is supported. Currently there can be at most one COUNT(DISTINCT) per query and an argument needs to be an attribute. Both current restrictions on COUNT(DISTINCT) might be lifted in the future.
也就是说只有在group by的时候才能用count(),如
select 1 as dummy,count() c from main_index group by dummy;
+------+--------+-------+--------+
| id | weight | dummy | @count |
+------+--------+-------+--------+
| 1001 | 1 | 1 | 15659 |
+------+--------+-------+--------+
第二种方法
select from main_index limit 0;
show meta;
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| total | 67 |
| total_found | 67 |
| time | 0.001 |
| keyword[0] | ha |
| docs[0] | 67 |
| hits[0] | 115 |
+---------------+-------+
也就是说用show meta来得到这个total_found,这个就是总记录数。
狼蚁网站SEO优化我们来说一下show meta:
SHOW META shows additional meta-information about the latest query such as query time and keyword statistics:
也就是说它显示的是最近一次查询附加的一些信息,比如查询时间、关键字统计、总记录等。
mysql> SELECT FROM test1 WHERE MATCH('test|one|two');
+------+--------+----------+------------+
| id | weight | group_id | date_added |
+------+--------+----------+------------+
| 1 | 3563 | 456 | 1231721236 |
| 2 | 2563 | 123 | 1231721236 |
| 4 | 1480 | 2 | 1231721236 |
+------+--------+----------+------------+
3 rows in set (0.01 sec)
mysql> SHOW META;
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| total | 3 |
| total_found | 3 |
| time | 0.005 |
| keyword[0] | test |
| docs[0] | 3 |
| hits[0] | 5 |
| keyword[1] | one |
| docs[1] | 1 |
| hits[1] | 2 |
| keyword[2] | two |
| docs[2] | 1 |
| hits[2] | 2 |
+---------------+-------+
12 rows in set (0.00 sec)
在PHP中如何调用?
<?php
//获取总记录个数
private function getTotalFound($conn) {
$sql = "show meta";
$total_result = @mysql_query ( $sql,$conn );
$totals = array ();
while ( ($row = mysql_fetch_assoc ( $total_result )) !== false ) {
$totals [$row ['Variable_name']] = $row ['Value'];
}
return $totals;
}
?>
注意如果代码中用了多个数据库连接的话,这个相应的conn必须传进来,否则是取不到结果的。
编程语言
- 如何快速学会编程 如何快速学会ug编程
- 免费学编程的app 推荐12个免费学编程的好网站
- 电脑怎么编程:电脑怎么编程网咯游戏菜单图标
- 如何写代码新手教学 如何写代码新手教学手机
- 基础编程入门教程视频 基础编程入门教程视频华
- 编程演示:编程演示浦丰投针过程
- 乐高编程加盟 乐高积木编程加盟
- 跟我学plc编程 plc编程自学入门视频教程
- ug编程成航林总 ug编程实战视频
- 孩子学编程的好处和坏处
- 初学者学编程该从哪里开始 新手学编程从哪里入
- 慢走丝编程 慢走丝编程难学吗
- 国内十强少儿编程机构 中国少儿编程机构十强有
- 成人计算机速成培训班 成人计算机速成培训班办
- 孩子学编程网上课程哪家好 儿童学编程比较好的
- 代码编程教学入门软件 代码编程教程