By 16 Jul 2004 14:59:24 -0700,
ba*************@yahoo.com (dan)
decided to post "Re: How to get a row count from a PHP/MYQSL db search"
to comp.lang.php:
leegold2 <le*****@nospam.net> wrote in message news:<q6*******************@nwrddc01.gnilink.net>. .. Below is some code from a FULLTEXT search. My question is how do I get a
count of the number of rows found by the search?
$query="SELECT * FROM balloon_txt WHERE MATCH(access_no, recs_txt)
AGAINST ('meteorology')";
$result = MySQL_query($query);
Thanks,
Lee G.
You could use SQL_CALC_FOUND_ROWS to get a count of returned rows
regardless of limit.
http://dev.mysql.com/doc/mysql/en/SELECT.html
example:
select SQL_CALC_FOUND_ROWS a,b,c from table limit 10; -- this returns
10 rows
select FOUND_ROWS(); -- this returns total count (i.e.: 1,587)
hth
I think that after your query (above) with SQL_CALC_FOUND_ROWS, you have to
run another query to get the count of results:
$countresult = mysql_query( "SELECT found_rows()" );
Also, this seems to return the proper full count of records produced by the
query, regardless of any query-limit set, but only_if_it_is_run_immediately
_after_the_first_query. The result of the first query is apparently stored
by php on the server, so it is not lost, and can be read and parsed
further. If another query is run first, if it includes the
SQL_CALC_FOUND_ROWS option, its count is returned; if it doesn't include
that option, I don't know how the result of a subsequent --
mysql_query( "SELECT found_rows()" );
-- would be defined....
Anther way I've used is:
$resultCount = mysql_num_rows($result);
but this shows how many rows are in the result, which would be equal to any
limit statement or be fewer than spec'd if fewer records are found than the
limit.
Both are useful in their own ways.
/ts
--
find / -iname "*gw*" -exec rm -rf {} \;
In heaven, there is no beer,
That's why we drink it here,
And when we're all gone from here,
Our friends will be drinking all the beer!
-- Famous old Czech song about beer --