Page 1 of 1

[Solved] Counting records

Posted: Fri Oct 26, 2012 9:31 pm
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.

Re: Counting records

Posted: Fri Oct 26, 2012 10:00 pm
by Jos

Re: Counting records

Posted: Sat Oct 27, 2012 6:16 am
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

Re: Counting records

Posted: Sat Oct 27, 2012 11:07 am
by musicscore
Thanks Duketown

It is working.

Musicscore

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