Forums

Count of rows

federici 11 Jul, 2012
Hi, i'm Claudio
i have a problem with a query inside the form.

My form should do only a count of rows of the table, i have made the form with only header text as element, and i have insert inside the Action -> On Load : Show Html and Custom Code

inside the Custom Code i have insert this code


<?php
        
    $db =& JFactory::getDBO();
    $query = "SELECT count(*) FROM jos_broken WHERE cf_modified='0000-00-00 00:00:00'";
    $db->setQuery($query);
    $db->query();
    $num_rows = $db->getNumRows();
    $echo($num_rows);
?>


but when i perform the form it don't work

i don't know if the problem is in the code or my use of chronoforms is not correct

thanks for help
GreyHead 11 Jul, 2012
Hi Claudio,

Please try:
<?php
$db =& JFactory::getDBO();
$query = "
  SELECT COUNT(*)
    FROM `#__broken` 
    WHERE `cf_modified` = '0000-00-00 00:00:00'
";
$db->setQuery($query);
$num_rows = $db->getResult(); // <-- see here
echo $num_rows; // and here (no $ in $echo)
?>

Bob
federici 12 Jul, 2012
i don't know why, but don't work

the query does not make the count😟
federici 12 Jul, 2012
ok perfect, it's work

i have change getNumRows() with loadResult() and the query works🙂
This topic is locked and no more replies can be posted.