PHP Classes

count rows not so efficient

Recommend this page to a friend!

      CRDB  >  All threads  >  count rows not so efficient  >  (Un) Subscribe thread alerts  
Subject:count rows not so efficient
Summary:count rows not so efficient
Messages:6
Author:geert van bommel
Date:2009-06-11 13:06:18
Update:2009-06-30 07:45:22
 

  1. count rows not so efficient   Reply   Report abuse  
Picture of geert van bommel geert van bommel - 2009-06-11 13:06:18
Hi,
I tested the class with a table of 10000 rows. To count the rows I have to do:
$rowset=$db->tablename();
$total=count($rowset);
I had no result returned. I guess due to a too large rowset.

So I added count to the class.

On row 268:

case 'total':
return new crdb_ext($this,'total');
**** I called it 'total' since 'count' is a php function. ****

and on row 648:

elseif($this->ext_name=='total'):
if(!empty($this->rowset->join_query)):
$full_field_name=$this->rowset->join_obj->join_aliases[$field];
$this->rowset->result_columns=" COUNT($full_field_name) as `$field`";
else:
$this->rowset->result_columns=" COUNT(`$field`) as `$field`";
endif;
return $this->rowset->$field;

Regards,
Geert

  2. Re: count rows not so efficient   Reply   Report abuse  
Picture of Sandeep.C.R Sandeep.C.R - 2009-06-12 09:04:26 - In reply to message 1 from geert van bommel
hi,

Thanks for using the class.

I checked the class with a table with 55000 rows.And it worked.I think you might be using an old version of this class.Can you send me the version of the file you are using? or can you with the latest version of this class and let me know the resutls?

Your method of finding the count is more efficient.But I just wanted to make it as simple as possible.

regards,
Sandeep.

  3. Re: count rows not so efficient   Reply   Report abuse  
Picture of geert van bommel geert van bommel - 2009-06-15 08:24:53 - In reply to message 2 from Sandeep.C.R
Hi,
I made sure I'm using the last version and I have the same result. The size of the table doesn't matter, but the amount of records returned does, I think.
If the table has 55000 rows, but the query returns 10000 rows then count($rowset) doesn't work anymore. Even stranger, the browser serves the script as a download.

Your method is indeed easier. Adding my method doesn't exclude users from choosing :-) It's a bit like doing mysql_query('select * from...') and then using mysql_num_rows to find the count, while 'select count(id) from ' uses less resources.

Other than that, happy using your class!
Regards,
Geert

  4. Re: count rows not so efficient   Reply   Report abuse  
Picture of Sandeep.C.R Sandeep.C.R - 2009-06-16 12:00:14 - In reply to message 3 from geert van bommel
hi,

i have modified the class not to store the result in array.Because you told the script is serverd as download, it should be running out of memory.So it shouldbe fixed now.

Regards,


  5. Re: count rows not so efficient   Reply   Report abuse  
Picture of geert van bommel geert van bommel - 2009-06-29 08:08:28 - In reply to message 4 from Sandeep.C.R
Hey,
sorry for the late reply. That fixed it! Thank you.

Regards,
Geert

  6. Re: count rows not so efficient   Reply   Report abuse  
Picture of Sandeep.C.R Sandeep.C.R - 2009-06-30 07:45:22 - In reply to message 5 from geert van bommel
Thanks for the reply, and glad to know that the issue has been fixed.

Regards,
Sandeep.