CodeIgniter Forums

Full Version: category wise listing in CodeIgniter
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

I want a category wise listing in CodeIgniter framework. Output will be like below format. It will be totally dynamic. Values (colors/red/blue/green etc) can be added/updated from back-end. Can anybody provide me the relevant codes for this?
<ul id="mylist">

El Forum

If you can make an array from it, gonna store it in database i guess?
id: no need to explain
name: whatever you want to output
parentid: ID of your parent

public function generate_ul_li($array, $html = '', $parent = 0, $level = 0, $firstloop = TRUE) {
        if ($array == NULL) {
            return false;
        $has_children = false;
        foreach ($array as $key => $value) {
            if ($value['parentid'] == $parent) {
                if ($has_children === false) {
                    $has_children = true;
                    if ($firstloop) {
                        $html .= '<ul id="mylist">';
                    } else {
                        $html .= '<ul>';
                 $html .= '<li>$value['name'] </a>';
                $this->generate_ul_li($array, $html, $value['id'], $level, FALSE);
                $html .= '</li>';
        if ($has_children === true)
            $html .= '</ul>';
        return $html;

call it generate_ul_li($yourarraywithvalues);