[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>";
}
?>
thank in advance
Krystian