Welcome Guest, Not a member yet? Register   Sign In
Model problem
#9

[eluser]shinokada[/eluser]
Model

Full

Code:
<?php
class MMenu2 extends Model{

    function MMenu(){
    parent::Model();
    }

    function generateTree($parentid = 0, &$tree) {
        
        $this->db->where ('parentid',$parentid);
        
        // $sql = 'SELECT * FROM menus WHERE parentid = $parentid';
        $res = $this->db->get('menus');
        if ($res) {
            foreach ($res->result() as $r) {
                // push found result onto existing tree
                $tree[$r->id] = $r;
                // create placeholder for children
                $tree[$r->id]['children'] = array();
                // find any children of currently found child
                $tree = $this->generateTree($r->id, $tree[$r->id]['children']);
            }
        }
    }

}
?>

Error

Full

Code:
Fatal error: Cannot use object of type stdClass as array in C:\xampp\htdocs\ci_menu\system\application\models\mmenu2.php on line 19

Full DB
Code:
CREATE TABLE IF NOT EXISTS `menus` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(255) NOT NULL,
  `shortdesc` varchar(255) NOT NULL,
  `status` enum('active','inactive') NOT NULL,
  `parentid` int(11) NOT NULL,
  `order` int(11) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=62 ;

--
-- Dumping data for table `menus`
--

INSERT INTO `menus` (`id`, `name`, `shortdesc`, `status`, `parentid`, `order`) VALUES
(24, 'Main menu', 'mainmenu', 'active', 0, 0),
(25, 'Galleri 1', 'galleri1', 'active', 0, 0),
(61, 'Design sub1', '', 'active', 59, 0),
(59, 'Design', '', 'active', 24, 0),
(60, 'illustrasjon 1', '', 'active', 25, 0);

-- --------------------------------------------------------

--
-- Table structure for table `tasks`
--

CREATE TABLE IF NOT EXISTS `tasks` (
  `task_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `parent_id` int(10) unsigned NOT NULL DEFAULT '0',
  `task` varchar(100) NOT NULL,
  `date_added` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `date_completed` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
  PRIMARY KEY (`task_id`),
  KEY `parent` (`parent_id`),
  KEY `added` (`date_added`),
  KEY `completed` (`date_completed`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=29 ;

--
-- Dumping data for table `tasks`
--

INSERT INTO `tasks` (`task_id`, `parent_id`, `task`, `date_added`, `date_completed`) VALUES
(25, 17, 'Grandchild of parent 1', '2009-12-08 12:37:09', '2009-12-08 12:37:09'),
(24, 17, 'Grandchild of parent 1', '2009-10-08 16:32:02', '0000-00-00 00:00:00'),
(22, 0, 'Parent 4', '2009-10-08 16:28:51', '0000-00-00 00:00:00'),
(23, 11, 'Child 2 of parent 1', '2009-10-08 16:29:07', '0000-00-00 00:00:00'),
(21, 0, 'Parent 3', '2009-10-08 16:28:43', '0000-00-00 00:00:00'),
(17, 11, 'Child 1 of parent 1', '2009-12-08 12:37:16', '2009-12-08 12:37:16'),
(19, 0, 'Parent 1', '2009-10-07 07:15:19', '0000-00-00 00:00:00'),
(20, 0, 'Parent 2', '2009-10-07 08:19:05', '2009-10-07 08:19:05'),
(11, 0, 'Parent1', '2009-10-05 21:30:16', '0000-00-00 00:00:00'),
(26, 11, 'write report', '2009-12-08 13:50:12', '0000-00-00 00:00:00'),
(27, 26, 'make exam', '2009-12-08 13:51:40', '0000-00-00 00:00:00'),
(28, 26, 'Pre IB exam', '2009-12-08 13:51:52', '0000-00-00 00:00:00');


Messages In This Thread
Model problem - by El Forum - 12-09-2009, 09:51 AM
Model problem - by El Forum - 12-09-2009, 09:57 AM
Model problem - by El Forum - 12-09-2009, 11:36 AM
Model problem - by El Forum - 12-09-2009, 11:47 AM
Model problem - by El Forum - 12-09-2009, 02:35 PM
Model problem - by El Forum - 12-09-2009, 02:54 PM
Model problem - by El Forum - 12-10-2009, 12:16 AM
Model problem - by El Forum - 12-10-2009, 12:21 AM
Model problem - by El Forum - 12-10-2009, 12:29 AM
Model problem - by El Forum - 12-10-2009, 12:46 AM
Model problem - by El Forum - 12-10-2009, 12:54 AM
Model problem - by El Forum - 12-10-2009, 12:59 AM
Model problem - by El Forum - 12-10-2009, 01:15 AM
Model problem - by El Forum - 12-10-2009, 01:23 AM
Model problem - by El Forum - 12-10-2009, 01:26 AM
Model problem - by El Forum - 12-10-2009, 01:30 AM
Model problem - by El Forum - 12-10-2009, 02:35 AM
Model problem - by El Forum - 12-10-2009, 08:28 AM
Model problem - by El Forum - 12-10-2009, 08:47 AM
Model problem - by El Forum - 12-10-2009, 09:43 AM
Model problem - by El Forum - 12-10-2009, 11:41 AM
Model problem - by El Forum - 12-10-2009, 12:20 PM
Model problem - by El Forum - 12-10-2009, 02:09 PM
Model problem - by El Forum - 12-10-2009, 02:29 PM
Model problem - by El Forum - 12-10-2009, 03:01 PM
Model problem - by El Forum - 12-10-2009, 05:58 PM
Model problem - by El Forum - 12-10-2009, 07:23 PM
Model problem - by El Forum - 12-10-2009, 08:53 PM
Model problem - by El Forum - 12-11-2009, 01:00 AM
Model problem - by El Forum - 12-11-2009, 01:07 AM
Model problem - by El Forum - 12-11-2009, 02:52 AM



Theme © iAndrew 2016 - Forum software by © MyBB