Forums

CC v2RC3 - Where SQL returns nr of records?

carestra 01 Oct, 2010
How can i check if the where clause returns a record?
I have try with <?php echo count($rows); ?> in the body and header section under the "Connection View Settings" but nothings is display.

I know that the where clause return at least one record since if a try using a field name, the data exist.
I have no (empty) where clause in the "WHERE SQL" section.
GreyHead 01 Oct, 2010
Hi carestra,

Put {column_name} in the section - with any valid column name from the table - there's a list you can check on the Admin Settings tab.

Bob
carestra 02 Oct, 2010
Hi Mr GreyHead,

Thanks for your advise, it seems that I did not explain may problem correctly.

This is my table:
Table name: YOYO
Column name : id - persname - age
record 1 : 3 - Kali - 12
record 2 : 5 - Yada - 65
record 3 : 45 - Mambo - 43

That I want to do is to display the number of records in the table YOYO.
There are 3 persons:
name: Kali
name: Mambo
name: Yada


I have try with <?php echo count($rows); ?> but the response is always 0 (zero) no matter the number of records in the table. How to I retreive the number of records that the WHERE SQL clause returns?

Thanks in advance
Carestra
GreyHead 02 Oct, 2010
Hi carestra,

Try this in the Header (or Footer) box.
<?php
$db =& JFactory::getDBO();
$query = "
    SELECT COUNT(*)
        FROM `YOYO` ;
";
$db->setQuery($query);
$count = $db->loadResult();
echo "<div>There are $count records in the table";
?>


Bob
carestra 02 Oct, 2010
Thanks, it works.

I don't understand the purpose of the "Query Related Settings" section.
I assume that the "where"-part just state
select * from YOYO WHERE XXX=='YYY'

It should return a result set just as the code snip "$db->setQuery($query);", why can't I just use that result set?
GreyHead 02 Oct, 2010
Hi carestra,

Yes the WHERE SQL box needs to return a WHERE clause like
WHERE `XXX` = 'YYY'
and the "Order Fields" box can contain a column name used to sort the table like `XXX` (but without the ORDER BY )

The other three boxes I have never used.

Bob
This topic is locked and no more replies can be posted.

VPS & Email Hosting 20% discount
hostinger