• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
category wise listing in CodeIgniter

#1
[eluser]Unknown[/eluser]
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">
<li>colors
<ul>
<li>red</li>
<li>blue</li>
<li>green</li>
</ul>
</li>
<li>shapes
<ul>
<li>round</li>
<li>suare</li>
<li>circles</li>
</ul>
</li>

#2
[eluser]noideawhattotypehere[/eluser]
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

Code:
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>';
                    }
                    $level++;
                }
                 $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);


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.