By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,725 Members | 1,048 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,725 IT Pros & Developers. It's quick & easy.

How to get a row count from a PHP/MYQSL db search

P: n/a
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.
Jul 17 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
On Fri, 16 Jul 2004 02:31:50 GMT, leegold2 <le*****@nospam.net> wrote:
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);


select count(*) from ball.....
--
gburnore@databasix dot com
---------------------------------------------------------------------------
How you look depends on where you go.
---------------------------------------------------------------------------
Gary L. Burnore | ۳ݳ޳ݳۺݳ޳ݳݳ޳ݳ۳
| ۳ݳ޳ݳۺݳ޳ݳݳ޳ݳ۳
DataBasix | ۳ݳ޳ݳۺݳ޳ݳݳ޳ݳ۳
| ۳ 3 4 1 4 2 ݳ޳ 6 9 0 6 9 ۳
Black Helicopter Repair Svcs Division | Official Proof of Purchase
================================================== =========================
Want one? GET one! http://signup.databasix.com
================================================== =========================
Jul 17 '05 #2

P: n/a
Gary L. Burnore wrote:
On Fri, 16 Jul 2004 02:31:50 GMT, leegold2 <le*****@nospam.net> wrote:

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);

select count(*) from ball.....


a search of the PHP docs is a good place to start:

$numrows = count(mysql_fetch_array($result))
or
$numrows = mysql_num_rows($result)

--
Michael Austin.
Consultant - Available.
Donations welcomed. Http://www.firstdbasource.com/donations.html
:)
Jul 17 '05 #3

P: n/a
dan
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
Jul 17 '05 #4

P: n/a
/..
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 --
Jul 17 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.