0

我正在制作一个搜索应用程序,我想弄清楚某个查询获取了多少结果,以便计算有多少页结果。我基本上有:

mysql_query("SELECT * FROM table WHERE conditions LIMIT $page*$items, $items");

我是否必须进行不带限制子句的查询才能获得总数,还是有更好的方法?谢谢!

4

4 回答 4

4
SELECT COUNT (*) FROM table WHERE conditions
于 2012-04-13T04:31:36.490 回答
3
SELECT COUNT(*)
  FROM table
  WHERE conditions
于 2012-04-13T04:31:44.073 回答
2

我看到你正在使用 PHP。一旦你运行了查询,你为什么不在mysql_num_rowsPHP 中呢?这样您就不需要运行两个查询。

于 2012-04-13T04:35:43.490 回答
0
$page_count=10 // no of rows per page 
$record=mysql_query("select count(*) from table where conditions");
$row=mysql_fetch_row[0];

$no_of_pages = ceil($row/$page_count);
于 2012-04-13T04:36:20.027 回答