Re: [PHP] Count number of rows in table.
And do I need to use any other functions like mysql_fetch_row() ? Martín marqués [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED]... On Sáb 24 Ago 2002 11:19, Tony Harrison wrote: How would I count the number of rows in a mysql table with a WHERE clause? select count(*) from table_name WHERE . Saludos... :-) -- Porqué usar una base de datos relacional cualquiera, si podés usar PostgreSQL? - Martín Marqués |[EMAIL PROTECTED] Programador, Administrador, DBA | Centro de Telematica Universidad Nacional del Litoral - -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Count number of rows in table.
On Sáb 24 Ago 2002 11:19, Tony Harrison wrote: How would I count the number of rows in a mysql table with a WHERE clause? Martín marqués [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED]... select count(*) from table_name WHERE . From: Tony Harrison [EMAIL PROTECTED] Sent: Saturday, August 24, 2002 5:54 PM Subject: Re: [PHP] Count number of rows in table. And do I need to use any other functions like mysql_fetch_row() ? Yes. It's a regular sql statement, so you must fetch the results. $sql = select count(*) from table_name WHERE .; $result = mysql_query($sql) or die(mysql_error); $row = mysql_fetch_row($result); $rowCount=$row[0]; -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Count number of rows in table.
$sql = select count(*) from table_name WHERE .; $result = mysql_query($sql) or die(mysql_error); $row = mysql_fetch_row($result); $rowCount=$row[0]; or $sql = select count(*) from table_name WHERE .; $result = mysql_query($sql) or die(mysql_error); $rowCount=mysql_result($result); -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Count number of rows in table.
or, you should be able to simply do this, without the cost of fetching the results: $result = mysql_query(SELECT count(*) FROM table WHERE); $num_rows = mysql_num_rows($result); echo $num_rows Rows\n; $sql = select count(*) from table_name WHERE .; $result = mysql_query($sql) or die(mysql_error); $row = mysql_fetch_row($result); $rowCount=$row[0]; or $sql = select count(*) from table_name WHERE .; $result = mysql_query($sql) or die(mysql_error); $rowCount=mysql_result($result); -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Count number of rows in table.
On Sunday 25 August 2002 22:07, salamander wrote: or, you should be able to simply do this, without the cost of fetching the results: $result = mysql_query(SELECT count(*) FROM table WHERE); $num_rows = mysql_num_rows($result); echo $num_rows Rows\n; No. This only returns 1 row regardless. SELECT COUNT(*) FROM ... only returns a single row with a single column containing the row count. Using mysql_num_rows() on that will always return 1. -- Jason Wong - Gremlins Associates - www.gremlins.com.hk Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * /* I'm going to Vietnam at the request of the White House. President Johnson says a war isn't really a war without my jokes. -- Bob Hope */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Count number of rows in table.
okay, so then a select * and then a num_rows ... On Sunday, August 25, 2002, at 10:11 AM, Jason Wong wrote: On Sunday 25 August 2002 22:07, salamander wrote: or, you should be able to simply do this, without the cost of fetching the results: $result = mysql_query(SELECT count(*) FROM table WHERE); $num_rows = mysql_num_rows($result); echo $num_rows Rows\n; No. This only returns 1 row regardless. SELECT COUNT(*) FROM ... only returns a single row with a single column containing the row count. Using mysql_num_rows() on that will always return 1. -- Jason Wong - Gremlins Associates - www.gremlins.com.hk Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * /* I'm going to Vietnam at the request of the White House. President Johnson says a war isn't really a war without my jokes. -- Bob Hope */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Count number of rows in table.
I think you were on the right track with your first response. Selecting a count(*) gives you the number of rows returned without the overhead of actually returning all of the rows to PHP. Most people will rename the count as something more easy to reference (and/or more descriptive) in the result set: select count(*) as num_movies from movies where actor='Val Kilmer'; What Jason was trying to explain is that the data you are looking for is actually in the query you performed. You specifically queried for the number of rows. Your result set consists of a single row with a single element, num_movies. Happy hacking. Chris salamander wrote: okay, so then a select * and then a num_rows ... On Sunday, August 25, 2002, at 10:11 AM, Jason Wong wrote: On Sunday 25 August 2002 22:07, salamander wrote: or, you should be able to simply do this, without the cost of fetching the results: $result = mysql_query(SELECT count(*) FROM table WHERE); $num_rows = mysql_num_rows($result); echo $num_rows Rows\n; No. This only returns 1 row regardless. SELECT COUNT(*) FROM ... only returns a single row with a single column containing the row count. Using mysql_num_rows() on that will always return 1. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php