Welcome Guest, Not a member yet? Register   Sign In
Confusion re loops for database results
#3

[eluser]Sumon[/eluser]
why not you use something like:
Code:
function get_maincat_info () {
$query = $this->db->query("SELECT Cat.cat_name, SCat.subcat_name, Item.item_name FROM maincategories Cat, subcategories SCat, iteminfo Item WHERE Cat.MainCatID=$maincatid and Cat.MainCatID=SCat.MainCatID and SCat.sub_cat_id=Item.sub_cat_id");
if ($query->num_rows() > 0)
   return $query->row_array();
}

writing model in this way will save your code in view as well.. use only single array
Code:
<?php foreach ($results as $row) { ?>
       &lt;?php echo $row->MainCatName;?&gt;<br>
&lt;?php endforeach;?&gt;

However please change my query... field name must not be same as you expect. Other will work fine Smile


Messages In This Thread
Confusion re loops for database results - by El Forum - 06-02-2008, 10:06 PM
Confusion re loops for database results - by El Forum - 06-03-2008, 04:12 AM
Confusion re loops for database results - by El Forum - 06-03-2008, 04:59 AM



Theme © iAndrew 2016 - Forum software by © MyBB