Welcome Guest, Not a member yet? Register   Sign In
Dadabase Generated Unordered List
#1

[eluser]Unknown[/eluser]
Hello,

I am trying to create a navigation menu with dynamic text coming from mySQL table.

View:

Code:
<ul class="menu_list">
          <li> <span class="toggle"><a href="#1">Cat 1</a> </span>
            <ul class="sublist">
              <li class="sublistLink"> <a href="#1">Cat 1</a></li>
              <li class="sublistLink"> <a href="#1">Cat 1.2</a></li>
              <li class="sublistLink"> <a href="#1">Cat 1.3</a></li>
              <li class="sublistLink"> <a href="#1">Cat 1.3</a></li>
            </ul>
          </li>
        
          <li class="toplink"> <a href="#1">Cat 2</a> </li>
          <li class="toplink"> <a href="#1">Cat 3</a></li>
          <li> <span class="toggle"><a href="#1">Cat 4</a></span>
            <ul class="sublist">
              <li class="sublistLink"> <a href="#1">Cat 4.1</a></li>
              <li class="sublistLink"> <a href="#1">Cat 4.2</a></li>
              <li class="sublistLink"> <a href="#1">Cat 4.3</a></li>
            </ul>
          </li>
          <li class="toplink"> <a href="#1">Cat 5</a></li>
          <li> <span class="toggle"><a href="#1">Cat 6</a></span>
            <ul class="sublist">
              <li class="sublistLink"> <a href="#1">Cat 6.1</a></li>
              <li class="sublistLink"> <a href="#1">Cat 6.2</a></li>
              <li class="sublistLink"> <a href="#1">Cat 6.3</a></li>
            </ul>
          </li>
          <li class="toplink"> <a href="#1">Cat 7</a></li>
          <li class="toplink"> <a href="#1">Cat 8 </a></li>
        </ul>
      </div>
      &lt;!--tools --&gt;
      <div class="left_column_tools_button width184 noRepeat">
        <h1> <a href="#1"></a> </h1>
      </div>
      <div class="left_tools_lists width186">
        <ul class="menu_list">
          <li> <span class="toggle"><a href="#1">Cat 9</a> </span>
            <ul class="sublist">
              <li class="sublistLink"> <a href="#1">Cat 9.1</a></li>
              <li class="sublistLink"> <a href="#1">Cat 9.2</a></li>
              <li class="sublistLink"> <a href="#1">Cat 9.3</a></li>
            </ul>
          </li>
          <li class="toplink"> <a href="#1">Cat 10</a> </li>
          <li class="toplink"> <a href="#1">Cat 11</a></li>
        </ul>
      </div>
      &lt;!--Finishes --&gt;
      <div class="left_column_finishes_button width184 noRepeat">
        <h1> <a href="#1"></a> </h1>
      </div>
      <div class="left_finishes_lists width186">
        <ul class="menu_list">
          <li> <span class="toggle"><a href="#1">Cat 12</a> </span>
            <ul class="sublist">
              <li class="sublistLink"> <a href="#1">Cat 12.1</a></li>
              <li class="sublistLink"> <a href="#1">Cat 12.2</a></li>
              <li class="sublistLink"> <a href="#1">Cat 12.3</a></li>
            </ul>
          </li>
          <li class="toplink"> <a href="#1">Cat 13</a> </li>
          <li> <span class="toggle"><a href="#1">Cat 14</a> </span>
            <ul class="sublist">
              <li class="sublistLink"> <a href="#1">Cat 14.1</a></li>
              <li class="sublistLink"> <a href="#1">Cat 14.2</a></li>
              <li class="sublistLink"> <a href="#1">Cat 14.3</a></li>
            </ul>
          </li>
        </ul>
      </div>

Model:

Code:
&lt;?php

class categoryModel extends Model{

    function categoryModel(){
        parent::Model();
    }

    function getCategory($id){

        $data = array();

        $where = array('cat_id' => $id);

        $query = $this->db->getwhere('categories',$where,1);

        if ($query-> num_rows() > 0){
            $data = $query->row_array();
        }

        $query->free_result();
        return $data;
    }

    function getAllCategories(){
        $data = array();
        $query = $this->db->get('categories');

        if ($query->num_rows() > 0){
            foreach($query->result_array() as $row){
            $data[] = $row;
            }
        }
        $query-> free_result();
        return $data;
    }
}

Controller:

Code:
&lt;?php

class Home extends Controller {

    function Home()
    {
        parent::Controller();
        $this->load->library('parser');
    }

    function index()
    {
        ini_set('display_errors', 1);
        ini_set('log_errors', 1);
        ini_set('error_log', dirname(__FILE__) . '/error_log.txt');
        error_reporting(E_ALL);
        
        $data['title']  = 'Building an e-commerce application using CodeIgniter ';
        $data['header'] = 'Header of the Test Page';
        $data['body']   = 'Test content here. Another content gooes here.';
      
        $id = '1'; //sample value of cat_id
        $productid = 'BMCGG18'; //sample value of cat_id
        
        //test our category model
        $myCat = $this->categoryModel->getCategory($id);
        //echo"hello";
        $data['myCat'] = $myCat['cat_name'];
        $data['allCategory'] = $this->categoryModel->getAllCategories();

        //test our product model
        $myProduct = $this->productsModel->getProduct($productid);

        $data['myProduct'] = $productid;
        $data['allProducts'] = $this->productsModel->getAllProducts();

        $this->parser->parse('sample_page', $data);
    }

}

In the categories table I have fields CAT1, CAT2, CAT3 and cat_id

Is anyone clever enough to help me?

Regards,
laanes
#2

[eluser]Dan Horrigan[/eluser]
I don't think anyone is clever enough to figure out exactly what your problem is. So mind explaining what the issue is?

Please don't say "It doesn't work"
#3

[eluser]Unknown[/eluser]
[quote author="Dan Horrigan" date="1273773321"]I don't think anyone is clever enough to figure out exactly what your problem is. So mind explaining what the issue is?

Please don't say "It doesn't work"[/quote]

This should explain my problem a bit more clearly:

Navigation Menu Screenshot

I would like the Department, Category and Subcategory to come from the tables I specified.

I hope this helps!

Regards,
laanes




Theme © iAndrew 2016 - Forum software by © MyBB