我正在尝试优化SQL请求的数量。
我发现我已经使用过两次相同的请求:

//a big select without limit
$select="select * from tab1, tab2 ,tab 3 where (jointure..)";

// return to me 20 line
$nbtotal=mysql_num_rows(mysql_query($select));
// I apply the limit for my paging system 5 per page
$select.=" limit  ".$offset.",".$limit;

// all the information that i need to fetch
$result_of_myrequest=mysql_query($select);


我已经尝试过count(article.id),但是每次计数它都会给我带来很大的收益!

我可以在同一请求(限制为0.5)中组合$ nbtotal和我的请求结果吗?

非常感谢!

最佳答案

运行限制查询,它将返回您的结果以显示,然后您可以调用另一个查询:

SELECT FOUND_ROWS();


这将返回上一个查询的总行数,而忽略该限制。

//a big select with limit
$select="select * from tab1, tab2 ,tab 3 where (jointure..) limit ".$offset.",".$limit;

// all the information that i need to fetch
$result_of_myrequest=mysql_query($select);

// return to me 20 line
$nbtotal = mysql_query("SELECT FOUND_ROWS()");

关于php - 有限制的结果总数,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/12843774/

10-12 00:02
查看更多