Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Displaying number of Rows

Status
Not open for further replies.

M2E

IS-IT--Management
Aug 1, 2005
28
GB
I would like to run a SELECT script and be able to just display the number of records it returns - how would I do this?

Is there a built in function like num_rows which would do this?



----Ment2Excel (M2E)----
--LEARN BY EXAMPLE--
 
...think I need to use COUNT in SQL - is this correct?

----Ment2Excel (M2E)----
--LEARN BY EXAMPLE--
 
You would be correct. COUNT in SQL will count all the affected rows and return the number as your result.

If you need the query and number of items in a query, I am afraid we do not have enough information to help you. PHP talks to a lot of databases and there are different commands for different dbs. In the most popular one, MySQL, you would use mysql_num_rows();.
 
If you only want to show how many rows there are, COUNT(*) will be faster, as none of the records are selected and/or returned.

eg:
SELECT COUNT(*) AS numrows FROM tablename;

is faster than:
SELECT * FROM tablename;

and then running mysql_num_rows();

it depends on what you want to do.

Olav Alexander Mjelde
Admin & Webmaster
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top