> I'm trying to get the total matched rows when I'm using "LIMIT 0, 10",
> but I only get the number 10, when the total should be around 100. So,
> can I get total matched rows without doing a separate query using
> count()?
>
> Here is an example of my current query:
>
> $result = mysql_query("SELECT * FROM products WHERE price<'10' ORDER BY
> price LIMIT 0, 10");
> $num_rows = mysql_num_rows($result);

Use two queries unless you are using MySQL 4.0+

FOUND_ROWS()
Returns the number of rows that the last SELECT SQL_CALC_FOUND_ROWS ...
command would have returned, if wasn't restricted with LIMIT.
mysql> SELECT SQL_CALC_FOUND_ROWS * FROM tbl_name
       WHERE id > 100 LIMIT 10;
mysql> SELECT FOUND_ROWS();
The second SELECT will return a number indicating how many rows the first
SELECT would have returned had it been written without the LIMIT clause.
Note that if you are using SELECT SQL_CALC_FOUND_ROWS ... MySQL has to
calculate all rows in the result set. However, this is faster than if you
would not use LIMIT, as the result set need not be sent to the client.
SQL_CALC_FOUND_ROWS is available starting at MySQL version 4.0.0.

---John Holmes...


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to