[Solved] Counting records

Talk about writing modules and plugins for CMS Made Simple, or about specific core functionality. This board is for PHP programmers that are contributing to CMSMS not for site developers
Post Reply
musicscore
Power Poster
Power Poster
Posts: 478
Joined: Wed Jan 25, 2006 11:53 am
Location: Netherlands

[Solved] Counting records

Post by musicscore »

I want to count record but it doesn't work.
My code is :

Code: Select all

	$query = 'SELECT COUNT(*) AS number FROM '.cms_db_prefix().'module_mfm_billing WHERE filename = ?';
    $dbresult = $db->Execute($query, array($filename));
	
	$countrecords = mysql_num_rows($dbresult); 
$countrecords stays empty

In my test I use a filename that is 2 time in the database.
When I look in the database there 2 records

Please help.
Last edited by musicscore on Sat Oct 27, 2012 11:08 am, edited 1 time in total.
Jos
Support Guru
Support Guru
Posts: 4019
Joined: Wed Sep 05, 2007 8:03 pm
Location: The Netherlands

Re: Counting records

Post by Jos »

Duketown

Re: Counting records

Post by Duketown »

musicscore,

Since you seem to be doing this from CMSMS I would stick with the functions available in CMSMS. There for I would write it something like this:

Code: Select all

$query = 'SELECT COUNT(*) AS number FROM '.cms_db_prefix().'module_mfm_billing WHERE filename = ?';
$dbresult = $db->GetRow($query, array($filename));
if ($dbresult) {
      $countrecords = $dbresult['number'];
}
It is not clear if the variable $filename is filled when you start the query, so that might be causing the problem as well.

Duketown
musicscore
Power Poster
Power Poster
Posts: 478
Joined: Wed Jan 25, 2006 11:53 am
Location: Netherlands

Re: Counting records

Post by musicscore »

Thanks Duketown

It is working.

Musicscore

(PS. See you on the 5th Dutch CMSMS Meeting. Any News ??)
Post Reply

Return to “Developers Discussion”