Welcome Guest, Not a member yet? Register   Sign In
Outputting Navigation from Database?
#1

[eluser]invision[/eluser]
Hi,

I have the following architecture for my web site:
Code:
Home
About Us
- Location
- The Team
Vacancies
News
Contact

My SQL table for the Menu currently looks like this:
Code:
id | title | url | category | main
1 | home | /index.php/page/ | 1 | 1
2 | about us | /index.php/aboutus/ | 2 | 1
3 | location | /index.php/aboutus/page/location | 2 | 0
......

Now, I want to take this data from my SQL table and display it in an unordered list in my web page. N.B. Whenever it's '1' in main category, this means it's the home page of a category.

So ultimately my HTML would be something like:

Code:
<ul>
<li>Home</li>
<li>About Us
<ul>
  <li>- Location</li>
  <li>- The Team</li>
</ul>
</li>
<li>Vacancies</li>
<li>News</li>
<li>Contact</li>


Here are some snippets of code I'm already using...

Controller(page.php)
Code:
$data['cats'] = $this->MPages->getPages();

Model(MPages.php)
Code:
function getPages(){
        $data = array();
        $Q = $this->db->get('pages');
        if ($Q->num_rows() > 0){
          foreach ($Q->result_array() as $row){
                   $data[$row['id']] = $row['title'];
                  }
        }
        $Q->free_result();    
        return $data;    
    }

Nav View(nav.php)
Code:
&lt;?php
if (count($cats)){
    foreach ($cats as $id => $title){
        echo anchor("page/$slug/",$title)."<br/>";
    }
}
?&gt;

However, I've got a bit stuck at this stage.

Anyone brave enough to help me out with this?



Many thanks for any pointers.


Messages In This Thread
Outputting Navigation from Database? - by El Forum - 03-02-2010, 01:08 PM
Outputting Navigation from Database? - by El Forum - 03-02-2010, 06:36 PM
Outputting Navigation from Database? - by El Forum - 03-03-2010, 07:13 PM
Outputting Navigation from Database? - by El Forum - 03-04-2010, 12:33 AM
Outputting Navigation from Database? - by El Forum - 06-24-2010, 03:09 PM



Theme © iAndrew 2016 - Forum software by © MyBB