Reply to Re: [PHP] Fast count of recordset in php...

Your name:

Reply:


Posted by Marcus Bointon on 09/29/93 11:23

On 7 Aug 2005, at 05:04, TalkativeDoggy wrote:

> 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];

According to the docs, MySQL has a particular optimisation that means
that it should be:

$sql = "SELECT COUNT(*) FROM tbvara WHERE Varunamn LIKE '$checkLev%'";

Also if you want the full count value when you've done a query that
uses a LIMIT clause, instead of doing a separate full count query,
you can get it by using the SQL_CALC_FOUND_ROWS keyword, e.g.

$sql = "SELECT SQL_CALC_FOUND_ROWS * FROM tbvara WHERE Varunamn LIKE
'$checkLev%' LIMIT 10";

Of course count(*) could only ever return up to 10 in this query -
you can find out how many it would have found by then asking:

$sql = "SELECT FOUND_ROWS()";

Marcus
--
Marcus Bointon
Synchromedia Limited: Putting you in the picture
marcus@synchromedia.co.uk | http://www.synchromedia.co.uk

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация