Thanks, re-read another component this morning and got it working. It
was my left join in the query causing an issue, for some reason the ID
number of the table gets replaced by the ID number of the other table.
Here is what my get list query looks like:
protected function getListQuery()
{
// Create a new query object.
$db = JFactory::getDBO();
$query = $db->getQuery(true);
$query->select('*');
// From the obituaries people table
$query->from('#__obituaries_comments AS a');
// Filter by published state.
$published = $this->getState('filter.state');
if (is_numeric($published)) {
$query->where('a.published = '.(int) $published);
}
elseif ($published === '') {
$query->where('(a.published IN (0, 1))');
}
// Filter by search in title
$search = $this->getState('filter.search');
if (!empty($search)) {
if (stripos($search, 'id:') === 0) {
$query->where('
a.id = '.(int) substr($search, 3));
} else {
$search = $db->Quote('%'.$db->escape($search, true).'%');
$query->where('(a.commentername LIKE '.$search.' OR b.lastname
LIKE '.$search.' OR b.firstname LIKE '.$search.' OR a.commenteremail
LIKE '.$search.')');
}
}
// Join over the categories.
$query->select('CONCAT(b.firstname,\' \',b.lastname) AS
obituary_name');
$query->join('LEFT', '#__obituaries_people AS b ON
b.id =
a.obituaryid');
// Add the list ordering clause.
$orderCol = 'a.datecreated';
$orderDirn = 'desc';
$query->order($orderCol.' '.$orderDirn);
return $query;
}
The end result works I retrive the name fine from the people table
however when I place $this->items and cycle through the ID for the
comments table is overwritten by the people table, is strange. When
doing a print_r() it looks like the left join is pulling all data from
the people table, when I only need 3 coloumns, so I guess this is why
ID is overwritten.
I am new to queries and still learning how the joins work, I have the
understanding a left join is what I need to match the id numbers and
then retrive the persons name.
I hope it makes sense and if you can see anything wrong with my query
I would appreciate any help you can offer.
Many thanks.