Q:

Code Igniter show Multiple results of a table depends upon another table ID

I have 2 tables name tbl_restaurant and tbl_restaurant_cuisines. what I am trying to do that I want the result of tbl_restaurant and also the result of tbl_restaurant_cuisines in relation with tbl_restaurant.
Below is the relation between the 2 tables
tbl_restaurant.id = tbl_restaurant_cuisines.restaurat_id
What I want to do 
For each restaurant there are multiple cuisines to show.
Like if we got the restaurant from restaurant table 
Dolphin(tbl_restaurant) then the cuisines will be Italian, Chinese, Indian(tbl_restaurant_cuisines) Like this
Restaurant Cuisine Table has the data like

Image of the tbl_restaurant_cuisines
Image of the tbl_restaurant

Where restaurant_id is the id of tbl_restaurant
I want to show this kind of results using Code Igniter.
What I have done is always showing the last result of tbl_restaurant_cuisines.
My Code
Model
//Function for getting the restaurant
    public function get_restaurant_results($search_suburb)
    {
        //$this->db->_protect_identifiers=false; 
        $query = $this->db->from('tbl_restaurant as tr, tbl_restaurant_servicearea as trs')
                          ->where('tr.id = trs.restaurant_id')
                          ->where('trs.servicearea_suburb', $search_suburb)
                          ->where('tr.status', 'approved')
                          ->get();
        //SELECT * FROM tbl_restaurant as tr, tbl_restaurant_servicearea trs WHERE tr.id = trs.resturant_id and trs.servicearea_suburb = '753010 - Cuttack';
        //$query = $this->db->query("SELECT * FROM tbl_restaurant as tr, tbl_restaurant_servicearea trs WHERE tr.id = trs.restaurant_id and trs.servicearea_suburb = '".$search_suburb."' and tr.status = 'approved'");
        $result = $query->result_array();
        return $result;
    }

    //Function for getting cuisin from searched restaurant
    public function get_restaurant_cuisines($restaurant_id)
    {
        $query = $this->db->where('restaurant_id= '.$restaurant_id.'')
                          ->get('tbl_restaurant_cuisines');

        //echo $restaurant_id;
        //$query = $this->db->query("SELECT * FROM tbl_restaurant_cuisines WHERE restaurant_id = $restaurant_id");
        $result = $query->result_array();
        return $result;
    }

Controller
public function restaurant_search()
    {
        if($this->session->userdata('username'))
        {
            $q = $this->userModel->getUserData($this->session->userdata('username')); 
            $data1 = $q[0];
            $data = array(
                'title'     =>'Restaurant Results',
                'fname'     =>$data1['fname'],
            );
        }
        else
        {
            $data = array(
                'title'     =>'Restaurant Results',
            );
        }
        $this->form_validation->set_rules('servicearea_suburb', 'Enter Pincode/ Suburb', 'required');

        if($this->form_validation->run() == FALSE)
        {
            // fails
            $data['title'] = 'Home Page';
            $this->load->view('header', $data);
            $this->load->view('home');
            $this->load->view('footer');
        }
        else
        {
            $search_suburb = $this->input->post('servicearea_suburb');
            $data['restaurants']  = $this->searchRestaurantModel->get_restaurant_results($search_suburb);

            //For Cuisin ID
            $res_cuisin = $data['restaurants'];
            foreach($res_cuisin as $res_id)
            {
                $data['cuisines'] = $this->searchRestaurantModel->get_restaurant_cuisines($res_id['restaurant_id']);
            }
            $data['servicearea_suburb'] = $search_suburb;
            $data['title'] = 'Restaurant Results';
            $data['count'] = count($data['restaurants']);
            $this->load->view('header', $data);
            $this->load->view('restaurants');
            $this->load->view('footer');
        }
    }

View
<?php
foreach($restaurants as $restaurant)
{
    echo $restaurant['restaurant_id'];
    echo $restaurant['restaurant_name']; 
    foreach($cuisines as $cuisine)
    {
        echo $cuisine['dealsin'];
    }
}
?>

I want this kind of result in CI like core PHP provided below.
<?php
$con = mysqli_connect("localhost","root","", "restaurant");
$sql = "SELECT * FROM tbl_restaurant where status='approved'";
$result = mysqli_query($con, $sql);
while($row = mysqli_fetch_array($result))
{
    $id = $row['id'];
    echo $name = "<h1>".$row['restaurant_name']."</h1><br>";
    $sql2 = "SELECT * FROM tbl_restaurant_cuisines WHERE restaurant_id = '".$id."'";

    $result2 = mysqli_query($con, $sql2);
    while($row2 = mysqli_fetch_array($result2))
    {   
        echo $cuisine = $row2['dealsin']."<br>";
    }
}
?>

A:

Replace your restaurant_search function in you controller as follow
public function restaurant_search()
{
    if($this->session->userdata('username'))
    {
        $q = $this->userModel->getUserData($this->session->userdata('username')); 
        $data1 = $q[0];
        $data = array(
            'title'     =>'Restaurant Results',
            'fname'     =>$data1['fname'],
        );
    }
    else
    {
        $data = array(
            'title'     =>'Restaurant Results',
        );
    }
    $this->form_validation->set_rules('servicearea_suburb', 'Enter Pincode/ Suburb', 'required');

    if($this->form_validation->run() == FALSE)
    {
        // fails
        $data['title'] = 'Home Page';
        $this->load->view('header', $data);
        $this->load->view('home');
        $this->load->view('footer');
    }
    else
    {
        $search_suburb = $this->input->post('servicearea_suburb');
        $get_restorent  = $this->searchRestaurantModel->get_restaurant_results($search_suburb);

        $restaurants = array();
        if(sizeof($get_restorent))
        {
          foreach($get_restorent as $res)
          {
            $temp = $res;
            $temp['cuisines'] = array();
            $get_cus = $this->searchRestaurantModel->get_restaurant_cuisines($res['restaurant_id']);
            if(sizeof($get_cus))
            {
              $temp['cuisines'] = $get_cus;
            }
            array_push($restaurants, $temp);
            $temp = array();
          }
        }

        $data['servicearea_suburb'] = $search_suburb;
        $data['title'] = 'Restaurant Results';
        $data['restaurants'] = $restaurants;
        $data['count'] = sizeof($restaurants);
        $this->load->view('header', $data);
        $this->load->view('restaurants');
        $this->load->view('footer');
    }
}

In your view page test with following code
<table border="1" cellpadding="5" cellspacing="5">
  <thead>
    <tr>
      <th>Restaurent ID</th>
      <th>Restaurent Name</th>
      <th>Available Cuisine</th>
    </tr>
  </thead>
  <tbody>
  <?php if(sizeof($restaurants)): foreach($restaurants as $res) ?>
    <tr>
      <<td><?=$res['id']?></td>
      <td><?=$res['restaurant_name']?></td>
      <td>
        <?php if(sizeof($res['cuisines'])): foreach($res['cuisines'] as $cus): ?>
          <?=$cus['dealsin'];?><br>
        <?php endforeach; else: ?>
          No Cuisines
        <?php endif; ?>
      </td>
    </tr>
  <?php endforeach; else: ?>
    <tr>
      <td colspan="3">Restaurent Not Found</td>
    </tr>
  <?php endif; ?>
  </tbody>
</table>

Update your code and let me know if it show any error.

