Rajan
Rajan

Reputation: 2425

How to show database records in bootstrap nav dropdown?

I Have a table called customer in which i have customer records.

Then i have table called Site, in which i have some two fields customer_id and site_key. Where site key is random generated license key.

Now I want to do something like this:

I want to show a nav bar in which the customer logged in can have a dropdown which will have its keys.

What i mean to say is A customer may have multiple site key so i want to fetch all the keys of that customer and show it in top nav bar dropdown.

I know the code for selecting the data from database, but i dont know how to display it the way i want.

Please Help

The Model Code:

public function get_user_license()
{
    $this->db->select('*');
    $this->db->join('tenant', 'sites.tenant_id = tenant.id');
    $this->db->from('sites');
    $query = $this->db->get();
    $result = $query->result(); 
    return $result; 
}

Upvotes: 0

Views: 375

Answers (1)

soni8010
soni8010

Reputation: 347

For controller

$this->data['sites']= $this->customer_user_m->get_user_license();

For model

             public function get_user_license()
        {


         $id = $this->session->userdata('id');

         $this->db->select('*');
         $this->db->where('tenant.id',$id);
         $this->db->join('tenant', 'sites.tenant_id = tenant.id');
         $this->db->from('sites');
         $query = $this->db->get();
         $result = $query->result(); 
         return $result; 
        }

The View:

<ul class="dropdown-menu">
        <li><a href="#">
        <?php

        foreach($sites as $site)
        {

        echo "<li>".$site->site_key."</li>";
        }

Upvotes: 1

Related Questions