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

#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);


Messages In This Thread
category wise listing in CodeIgniter - by El Forum - 10-01-2013, 10:54 PM
category wise listing in CodeIgniter - by El Forum - 10-02-2013, 12:58 AM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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