ChronoEngine.com homepage

Forums

Please write a review for the extension you are using on the Joomla extensions directory before posting a new question as we are being spammed by many negative reviews.

Thank you for your support!

Count rows with COUNT statement

tnijman 19 Jan, 2009
<?php
$database2 =& JFactory::getDBO();
$query3 = "SELECT COUNT(*) FROM #__chronoforms_gastenlijst WHERE cf_user_id = '63'";
$database2->setQuery($query3);
$row2 = $database2->loadObject();
echo $database2->getErrorMsg();
echo $row2->COUNT(*);
?>

the query works in phpmyadmin, it just doesn't show me anything in php. is there anything wrong with my code?

Thanks
GreyHead 19 Jan, 2009
Hi tnijman,

Try this
<?php
$database2 =& JFactory::getDBO();
$query3 = "SELECT COUNT(*) FROM #__chronoforms_gastenlijst WHERE cf_user_id = '63'";
$database2->setQuery($query3);
if ( !($row2 = $database2->loadResult()) { // you will only get a single result 
    echo $database2->getErrorMsg();
}
echo $row2;
?>
Bob

PS Why $database2?
tnijman 19 Jan, 2009
I put the code you gave me in the header of a chronoformconnection. The onlything it displays is the loop without any styling. Without the table I made it in. Any suggestions?

Thanks!

PS I didn't know what the problem was at first point: when I made another server connection it filtered things out. At that point I renamed some variables and it worked.. That's the reason.
GreyHead 20 Jan, 2009
Hi tnijman,

There's no table code in this thread so I really don't know what you are asking??

Bob
tnijman 20 Jan, 2009
It just doesn't show anything. But the query in phpmyadmin works
tnijman 20 Jan, 2009
I did it a different way: count($rows)
thanks for the help!
This topic is locked and no more replies can be posted.

2Checkout.com

2CheckOut.com Inc. (Ohio, USA) is an authorized retailer for goods and services provided by ChronoEngine.com