Welcome Guest, Not a member yet? Register   Sign In
my own helper creating menu
#1

[eluser]Krystian[/eluser]
Hi,

I`m trying to create dropdown menu from db. Now just for example

helper

Code:
<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

if ( ! function_exists('create_menu'))
{
    function display_menu($parent, $level) {
    
        $query = $this->db->get('menu');
        
        return $query->result();
        
        
    
    }
}

controller
Code:
<?php
class Main extends CI_Controller {

    
    function __construct()
    {
        parent::__construct();
    }    

    public function index()
    {
        $data['title'] = "Elcometer";
        
        
        $data['menu'] = dispaly_menu(0,1);
        
        $this->load->view('main_view', $data);
    }
    
}
?>

view

Code:
<?php

    foreach($menu as $menus)
    {
        echo $menus->label;
    }

?>
and I get Call to undefined function dispaly_menu()

in this simple example I would like to retrieve some data from db using helper. Or maybe I should put it into model and then use model method in helper. Can someone give me a correct tip/code to do this?


p.s. my function creating menu

Code:
<?php
    function display_menu($parent, $level) {
    
        $result = mysql_query("SELECT a.id, a.label, a.link, Deriv1.Count FROM `tree2` a  LEFT OUTER JOIN (SELECT parent, COUNT(*) AS Count FROM `tree2` GROUP BY parent) Deriv1 ON a.id = Deriv1.parent WHERE a.parent=" . $parent);
    
        echo "<ul id='nav'>";
    
        while ($row = mysql_fetch_assoc($result)) {
    
            if ($row['Count'] > 0) {
    
                echo "<li><a href='" . $row['>" . $row['label'] . "</a>";
    
                display_children($row['id'], $level + 1);
    
                echo "</li>";
    
            } elseif ($row['Count']==0) {
    
                echo "<li><a href='" . $row['>" . $row['label'] . "</a></li>";
    
            } else;
    
        }
    
        echo "</ul>";
    
    }
?&gt;
thank in advance
Krystian


Messages In This Thread
my own helper creating menu - by El Forum - 08-13-2011, 07:05 AM
my own helper creating menu - by El Forum - 08-13-2011, 10:37 AM
my own helper creating menu - by El Forum - 08-13-2011, 11:25 AM
my own helper creating menu - by El Forum - 08-13-2011, 12:04 PM
my own helper creating menu - by El Forum - 08-13-2011, 12:10 PM
my own helper creating menu - by El Forum - 08-13-2011, 12:14 PM
my own helper creating menu - by El Forum - 08-13-2011, 12:23 PM
my own helper creating menu - by El Forum - 08-13-2011, 12:42 PM
my own helper creating menu - by El Forum - 08-13-2011, 12:51 PM
my own helper creating menu - by El Forum - 08-13-2011, 01:17 PM
my own helper creating menu - by El Forum - 08-13-2011, 01:33 PM
my own helper creating menu - by El Forum - 08-13-2011, 07:06 PM
my own helper creating menu - by El Forum - 08-14-2011, 02:31 AM
my own helper creating menu - by El Forum - 08-14-2011, 04:04 AM
my own helper creating menu - by El Forum - 08-14-2011, 05:53 AM
my own helper creating menu - by El Forum - 08-14-2011, 06:28 AM
my own helper creating menu - by El Forum - 08-15-2011, 07:11 AM
my own helper creating menu - by El Forum - 08-15-2011, 07:34 AM
my own helper creating menu - by El Forum - 08-15-2011, 07:37 AM



Theme © iAndrew 2016 - Forum software by © MyBB