RE: [PHP] next page records (done, but a little problem. -OT-)
| From: | John W. Holmes | Date: | Sat, 03 May 2003 00:59:59 +0000 |
| Subject: | RE: [PHP] next page records (done, but a little problem. -OT-) | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-146214@lists.php.net to get a copy of this message | ||
> Thanks to the links given to me by the kind people here I have
findished
> "paginating" one of my scripts...I just have one little problem,
instead
> of
> using "COUNT" this method is using "mysql_num_rows" as you can imagine
if
> you have a large amount of records this is not a good solution but
somehow
> I
> am unable to implement "COUNT" into this so I am includeing the code
below
> in its original form for any suggestions from you guys.
> How can i take out the mysql_num_rows and add "count" instead?
[snip]
> $query_count = "SELECT * from $tcname";
> $result_count = mysql_query($query_count);
> $totalrows = mysql_num_rows($result_count); // **** this is
what i
> want to take out and put "count()"
$query_count = "SELECT COUNT(*) FROM $tcname";
$result_count = mysql_query($query_count);
$total_rows = mysql_result($result_count,0);
or
$query_count = "SELECT COUNT(*) FROM $tcname";
$result_count = mysql_query($query_count);
$row = mysql_fetch_row($result_count);
$total_rows = $row[0];
or
$query_count = "SELECT COUNT(*) AS c FROM $tcname";
$result_count = mysql_query($query_count);
$row = mysql_fetch_assoc($result_count);
$total_rows = $row['c'];
---John W. Holmes...
PHP Architect - A monthly magazine for PHP Professionals. Get your copy
today. http://www.phparch.com/