select count(*) from table_name WHERE .....
Saludos... :-)
--
Porqué usar una base de datos relacional cualquiera,
si podés usar PostgreSQL?
-----------------------------------------------------------------
Martín Marqués | mmar...@unl.edu.ar
Programador, Administrador, DBA | Centro de Telematica
Universidad Nacional
del Litoral
-----------------------------------------------------------------
"Martín marqués" <mar...@bugs.unl.edu.ar> wrote in message
news:200208241133...@bugs.unl.edu.ar...
>From: "Tony Harrison" <ton...@tharrison21.fsnet.co.uk>
> 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];
$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
>
>
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
*/
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