如何从CodeIgniter中的其他表获取Name

时间:2016-08-19 14:40:17

标签: php mysql codeigniter

我需要通过表的id来从其他表中获取名称

以下是“风味”表格内容

enter image description here

下面是“销售”表格内容 enter image description here

在我的控制器中,我正在使用此功能

 public function index() {
    if (!$this->ion_auth->in_group(array('admin'))) {
        redirect('home/permission');
    }
    $data['settings'] = $this->settings_model->getSettings();
    $data['all_sales'] = $this->sales_model->getAllSales();
    $data['flavour_name'] = $this->sales_model->getFlavourById($flavour_id);
    $this->load->view('home/dashboard', $data); // just the header file
    $this->load->view('sales/index', $data); 
    $this->load->view('home/footer'); // just the header file
}

在模型中,我正在使用此功能

function getFlavourById($flavour_id) {
    $this->db->select('*');
    $this->db->from('sales');
    $this->db->join('flavours', 'flavour_id.id = name.id');
    $query = $this->db->get(); 
}

在视图中我正在使用此

<?php foreach ($all_sales as $sale) { ?>
<tr class="">
    <td> <?php echo $sale->date; ?></td>
    <td> <?php echo $sale->name; ?></td>
    <td><?php echo $sale->flavour_name; ?></td> <!--- Need Flavour Name Here --->
    <td><?php echo $sale->mac_id; ?></td>
    <td><?php echo $sale->hdd_id; ?></td>

0 个答案:

没有答案