Welcome Guest, Not a member yet? Register   Sign In
How could I either combine this query or send these to the view correctly?
#2

[eluser]Armchair Samurai[/eluser]
This makes the assumption that the parent column contains a number which refers to the id column.

In the model:
Code:
$this->db->select('x.id, x.name, y.name AS parent');
$this->db->join('categories AS y', 'x.parent = y.id');
$this->db->where('x.type', 'product');
$this->db->where('x.parent !=', 0);
$this->db->where('x.active', 'Y');
$this->db->where('y.active', 'Y');
$this->db->orderby('x.parent', 'asc');
$query = $this->db->get('categories AS x');

In the view:
Code:
<?php

$parent = '';

foreach ($categories as $category):

if ($category->parent != $parent):

$parent = $category->parent;

echo $parent.'<br />';

endif; ?&gt;
--&lt;?=category->name;?&gt;<br />
&lt;?php endforeach; ?&gt;


Messages In This Thread
How could I either combine this query or send these to the view correctly? - by El Forum - 01-22-2008, 01:02 AM



Theme © iAndrew 2016 - Forum software by © MyBB