I have the following query in Codeigniter:
$this->db->select('p.productionId, p.name, p.year, p.poster, p.description_nl, p.story_nl, p.castCrew_nl, p.description_en, p.story_en, p.castCrew_en, GROUP_CONCAT(g.galleryId,".",g.name_nl) AS name_nl, GROUP_CONCAT(g.galleryId,".",g.name_en) AS name_en, COUNT("gi.url") AS url')->from('productions p');
$this->db->join('galleries g', 'g.productionId = p.productionId', 'left');
$this->db->join('galleryImages gi', 'gi.galleryId = g.galleryId', 'left');
$this->db->group_by('p.productionId');
$this->db->order_by('p.name', 'ASC');
$this->db->order_by('p.name, gi.galleryId', 'ASC');
$query = $this->db->get();
return $query->result();
The output this delivers is that each g.name_nl and g.name_en is part of a production ID, and hence puts those with the correct ID in a PHP foreach.
However, in that same foreach I want to show a count of the amount of URLS belong with that same gallery, which joins with the
$this->db->join('galleryImages gi', 'gi.galleryId = g.galleryId', 'left');
line in the code.
The error this results in, is that it listsall name_nl's and name_en's, rather than that it groups than if there are multiple rows.
How do I correct this?
-- update -- Foreach
<?php foreach ($productions as $production) { ?>
<h3><?php echo $production->name; ?> (<?php echo $production->year; ?>)</h3><br />
echo $production->name_nl;
echo $production->url;
} ?>
Which results in: A A A B A
Rather than A B 5