List Template - Add PHP to Grouped Row

SteveRL

Member
I'm grouping a list on a Date field. The 'group by' has access set to 'Nobody' so it never changes.
I'm modifying the default.php of a template and what I want to do is get the first record of the group and run a query to add related info to the group line. Getting the id of the first record in the group, or even the value (date) of the 'group by' would work.

I can use the code below to do something similar in default_row.php but when I do it in default.php it seems to be giving me the previous record, which is in a different group.

Code:
$note= $this->_row->data->schedule___note_raw;
echo $note;
 
Actually it looks like what I needed is just
Code:
echo $groupedBy;
Now the question becomes, am I able to run a query on the database inside this default.php file? I'm receiving errors when I follow the PHP Common Tasks.
 
Thanks for the response Hugh, I actually got it working, I think the errors I was getting were related to not encapsulating my datetime in the query. Here is the working code:

Code:
<!-- Steve added to display the last edit of the day -->

<span class="lastModified">
<?php

date_default_timezone_set('America/Los_Angeles');

$Date = $groupedBy;
$DateForm = date('Y-m-d H:i:s', strtotime($Date));

$myDb = JFactory::getDbo();
$myQuery = $myDb->getQuery(true);

$myQuery = "
select modified FROM schedule
WHERE event_date = '$DateForm'
ORDER BY modified desc LIMIT 1;
";

$myDb->setQuery($myQuery);
$LastModified = $myDb->loadResult();


$LastModifiedFormatted =  'Last modified: ' . date('M j, Y \a\t H:i',strtotime("$LastModified UTC")) . ' hours';

echo $LastModifiedFormatted;

?>
</span>
<!-- End Steve added to display last edit of the day -->
 
I would advise against using date_default_timezone_set(), and instead use the J! date class, with TZ handling.

But if it works ...

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

Thank you.

Members online

No members online now.
Back
Top