473,326 Members | 2,126 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

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

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
4 11190
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
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
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
/..
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: cassandra.flowers | last post by:
Hi, I have another string handling question for the group, since you have all been so helpful in the past. Thank you. Basically, I want to do something really simple: Search a main...
10
by: Anand Pillai | last post by:
To search a word in a group of words, say a paragraph or a web page, would a string search or a regexp search be faster? The string search would of course be, if str.find(substr) != -1:...
2
by: CharitiesOnline | last post by:
Hello, I have set this script up to add paging to a search results page. Which on the first page works fine. I calculates how many pages there should be depending on the number of results returned...
0
by: todd | last post by:
here is a search tool SP I wrote. How many times have you wanted to search all your Stored procs or views (in a database) for a keyword but couldn't!? Well now you can! THis can makes life a...
83
by: D. Dante Lorenso | last post by:
Trying to use the 'search' in the docs section of PostgreSQL.org is extremely SLOW. Considering this is a website for a database and databases are supposed to be good for indexing content, I'd...
3
by: ZafT | last post by:
Thanks for any help in advance. I am using this exact same piece of code on a server running PHP4, but for some reason when I run it on dreamhost using PHP5, the search does not register and it...
4
by: jackloanshark | last post by:
Hello, I am a beginner of c. I wrote a program about counting words in a txt file.But actually there are some error in it and it will stop counting at the first paragraph and just return the number...
2
by: slizorn | last post by:
hi guys, i need to make a tree traversal algorithm that would help me search the tree.. creating a method to search a tree to find the position of node and to return its pointer value basically i...
0
by: JamesOo | last post by:
I have the code below, but I need to make it searchable in query table, below code only allowed seach the table which in show mdb only. (i.e. have 3 table, but only can search either one only,...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.