I have a custom joomla MVC component. The component has a table of items, and a table of bids to deliver those items.
I have figured out how to display a list the relevant 'bids' on the view for an 'item' by adding this to the item model:
public function getBidsById($id) {
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query
->select('*')
->from('#__entrusters_bids ')
->where('item_id = ' . $id);
$db->setQuery($query);
$db->query();
return $db->loadObjectList();
}
This to the views/item/view.html.php:
$model = $this->getModel('Item', 'EntrustersModel');
$itemID = jRequest::getVar('id');
$bidsOnItem = $model->getBidsById($itemID);
$this->bidsOnItem = $bidsOnItem;
And e.g. this to the views/item/tmpl/default.php:
var_dump($this->items_by_id);
That all works fine.
Here's the actual question:
Now i need to show a COUNT of the bids on the LIST view (items - with an s) within each row of the foreach.
What is the BEST way of achieving this? I have tried adding the same to the items model and views/items/view.html.php, then I attempted something like this in the list:
<ul>
<?php foreach ($this->items as $item) : ?>
<li>Item stuff about the item. This item has <?php echo count($item->bidsOnItem); ?> bids</li>
<?php endforeach; ?>
</ul>
But that just returns 0 - not the count of bids on each item in the list. Grateful for help from the MVC experts out there.