Welcome Guest, Not a member yet? Register   Sign In
how can I make loop within a loop in codeigniter?
#1

[eluser]zoreli[/eluser]
Hi

I have table faq_categories with following fields

Code:
CREATE TABLE IF NOT EXISTS `faq_categories` (
  `catid` int(11) NOT NULL AUTO_INCREMENT,
  `categoryname` varchar(37) NOT NULL,
  `parentid` int(11) DEFAULT NULL,
  `description` text NOT NULL,
  `metatags` text NOT NULL,
  `sorder` int(11) NOT NULL,
  `visible` tinyint(4) NOT NULL,
  `categoryphoto` varchar(255) NOT NULL,
  PRIMARY KEY (`catid`),
  KEY `parentid_fk` (`parentid`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=52 ;


In my php code I have the following code :


Code:
$query="SELECT * FROM categories";
    $result=mysql_query($query);
    $num=mysql_num_rows($result);
    $i=0;
    while ($i < $num) {
        $id=mysql_result($result,$i,"id");
        $name=mysql_result($result,$i,"name");
        $parentid=mysql_result($result,$i,"parentid");
        $categoryphoto=mysql_result($result,$i,"categoryphoto");
        $sorder=mysql_result($result,$i,"sorder");
        $visible=mysql_result($result,$i,"visible");
      

echo $id;

echo $name;

// THIS IS WHAT I DON'T KNOW HOW TO DO IN CODEIGNITER
// HOW TO GET THE CATEGORYNAME ON BASE ON PARENTID

if ($parentid) {
                        
                        //echo $parentid;
                         $query1="SELECT name as parentname FROM categories WHERE id = ".$parentid;
                         echo mysql_result(mysql_query($query1),0,"parentname");
                        
                        } else {
                            echo "Root Category";
                        }

How can I do this in codeigniter? If possible, I would like to avoid joins.

Regards, Zoreli


Messages In This Thread
how can I make loop within a loop in codeigniter? - by El Forum - 02-17-2012, 01:43 AM
how can I make loop within a loop in codeigniter? - by El Forum - 02-17-2012, 08:45 AM
how can I make loop within a loop in codeigniter? - by El Forum - 02-17-2012, 09:54 AM



Theme © iAndrew 2016 - Forum software by © MyBB