Welcome Guest, Not a member yet? Register   Sign In
Menu with subitems from DB - CI noob
#1

[eluser]Unknown[/eluser]
Hello,

being new to codeigniter (and not feeling comfortable around OOP & MVC just yet), I struggling with a particular page element - main menu driven from a db table.

The db table is in attachment.

Here is what I wish to achieve:

1. read and return all items from table that have parent_id = 0 (or just all items and filter the array later)
2. check if there are any records in table where parent_id=id of current record
3. if there are none render in view as <li> element, if there are some render in view as <li class="dropdown"> element with css class
4. if subitems found read all that records from db that has a parent_id=id and render

pseudocode would be something like that:

Code:
$q_parent=db->query(SELECT * FROM tbl_menus WHERE parent_id=0);
$r_parent=db->records_array($q_parent);
for each ($r_parent){
  $check = $r_parent['id'];
  $q_child=db->query(SELECT * FROM tbl_menus WHERE parent_id=$check);
  if ($q_child->numrows = 0){
         echo '<li>'.$r_parent['display_name'].'</li>'; //render list element
     } else {
    echo '<li class="dropdown">'.$r1['display_name'].'<ul>'; //reder list element & open internal <ul>
    $r_child=db->records_array($q_child);
    for each ($r_child){
       echo '<li>'.$r_child['display_name'].'</li>'; //render internal list element
    }
echo '</ul></li>'; // close internal <ul> and  dropown <li>
}

so far, using CI tutorials I am able to list the parent elements, bu nothing else


Messages In This Thread
Menu with subitems from DB - CI noob - by El Forum - 02-02-2014, 07:04 AM
Menu with subitems from DB - CI noob - by El Forum - 02-02-2014, 08:10 AM
Menu with subitems from DB - CI noob - by El Forum - 02-02-2014, 12:32 PM
Menu with subitems from DB - CI noob - by El Forum - 02-02-2014, 03:28 PM
Menu with subitems from DB - CI noob - by El Forum - 02-04-2014, 02:45 AM



Theme © iAndrew 2016 - Forum software by © MyBB