|
Posted by "Gustav Wiberg" on 10/04/94 11:23
Hi again!
Thanx!!! I think this will help a lot!!!
/mr G
@varupiraten.se
----- Original Message -----
From: "TalkativeDoggy" <talkativedoggy@gmail.com>
To: "Sebastian" <sebastian@broadbandgaming.net>
Cc: "Gustav Wiberg" <gustav@varupiraten.se>; <php-general@lists.php.net>
Sent: Sunday, August 07, 2005 6:04 AM
Subject: Re: [PHP] Fast count of recordset in php...
> 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@broadbandgaming.net>
>>> To: "Gustav Wiberg" <gustav@varupiraten.se>
>>> Sent: Saturday, August 06, 2005 11:08 PM
>>> Subject: Re: [PHP] 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
>
>
>
> --
> No virus found in this incoming message.
> Checked by AVG Anti-Virus.
> Version: 7.0.338 / Virus Database: 267.10.0/63 - Release Date: 2005-08-03
>
>
[Back to original message]
|