• Hello Fabrik Community

    Fabrik is now in the hands of the development team that brought you Fabrik for Joomla 4. We have recently transitioned the Fabrik site over to a new server and are busy trying to clean it up. We have upgraded the site to Joomla 4 and are running the latest version of Fabrik 4. We have also upgraded the Xenforo forum software to the latest version. Many of the widgets you might have been used to on the forum are no longer operational, many abandoned by the developers. We hope to bring back some of the important ones as we have time.

    Exciting times to be sure.

    The Fabrik 4.0 Official release is now available. In addition, the Fabrik codebase is now available in a public repository. See the notices about these in the announcements section

    We wish to shout out a very big Thank You to all of you who have made donations. They have really helped. But we can always use more...wink..wink..

    Also a big Thank You to those of you who have been assisting others in the forum. This takes a very big burden off of us as we work on bugs, the website and the future of Fabrik.

PHP code in Form intro

dimoss

Well-Known Member
Hi

I am trying to include the following PHP script using Sourcener to get the total count of id's of a list
PHP:
<?php
 
$db = JFactory::getDBO();
 
$db->setQuery("SELECT COUNT('id') FROM 'fab_adeies'");
 
$number = $db->loadResult();
 
echo "The total number is: ".$number;
?>
However I can't get it work. It returns nothing instead of the number expected.

I tried also to put the same code in an J! article but again no number.

Any help?

Thanks
 
Finally found it. I made some changes in the code:

PHP:
<?php
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select('COUNT(*)');
$query->from('fab_adeies');
$db->setQuery($query);
$number = $db->loadResult();
echo 'The total number is: '.$number;
?>
 
Cool. My next suggestion was going to be exactly that. Although it's sometimes easier to just write a simple string query, it's good to get in the habit of using the query builder API.

-- hugh
 
Hmmm, for some reason my previous post never made it, I think i was having connectivity issues yesterday. My first suggestion had been to assign an alias name to the count. I seem to recall that for some reason you have to name it when doing loadResult(), if you aren't using the query builder. So "SELECT COUNT(*) AS somename".

-- hugh
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top