|
Posted by Marcus Bointon on 10/04/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
Navigation:
[Reply to this message]
|