Re: Fast count of recordset in php...

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



if you just wana get count of recordset,
don't do this:
$sql = mysql_query("SELECT col FROM tbvara WHERE Varunamn LIKE '$checkLev%'");
// record count
echo mysql_num_rows($sql);

be coz this way is slow and costs more overload.

$sql = "SELECT COUNT(IDVara) cn FROM tbvara WHERE Varunamn LIKE '$checkLev%'";
   $querys = mysql_query($sql);

   //Count products in db
   //
   $dbArray = mysql_fetch_row($querys);
   $nrOfProducts = $dbArray[0];

Sebastian wrote:
you'd be suprized how fast an index can be.. you should read the manual on indexes,
http://dev.mysql.com/doc/mysql/en/mysql-indexes.html

"If a table has 1,000 rows, this is at least 100 times faster than reading sequentially"

while you may not get 100x faster, it will be faster than having no index.. also try using mysql_num_rows()

$sql = mysql_query("SELECT col FROM tbvara WHERE Varunamn LIKE '$checkLev%'");
// record count
echo mysql_num_rows($sql);


PS, 'reply all' to list.

Gustav Wiberg wrote:

Hi there!

There are about 300 records.
You're right, I can add an index, but Is that the only way to get a faster solution?

/mr G
@varupiraten.se

----- Original Message ----- From: "Sebastian" <sebastian@xxxxxxxxxxxxxxxxxxx>
To: "Gustav Wiberg" <gustav@xxxxxxxxxxxxxx>
Sent: Saturday, August 06, 2005 11:08 PM
Subject: Re:  Fast count of recordset in php...


how many records in the table? its going to be slow no matter what, especially if you have a lot of records.. your searching each record then counting them.. do you have any indexes? judging by your query you can add index on Varunamn and it should be more speedy..

Gustav Wiberg wrote:

Hello there!

How do i get a fast count of a recordset in php?

Look at this code:

$sql = "SELECT COUNT(IDVara) cn FROM tbvara WHERE Varunamn LIKE '$checkLev%'";
   $querys = mysql_query($sql);

   //Count products in db
   //
   $dbArray = mysql_fetch_array($querys);
   $nrOfProducts = $dbArray["cn"];


It's slow... Why? Any suggestions?

/mr G
@varupiraten.se

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux