简体   繁体   English

加入codeigniter返回多个值

[英]join in codeigniter returns multiple values

I have a problem joining two tables. 连接两个表时出现问题。 In my first table, I want to retrieve 1 row for the time, and in the 2nd table I want to retrieve the table_number and table_sizes with both table having the same key which is the resto_id. 在我的第一个表中,我想检索一次该行,在第二个表中,我想检索table_number和table_sizes,两个表具有相同的键,即resto_id。 But it seems to return repeating values for the time. 但是它似乎返回该时间的重复值。 I've tried using group_by but it didnt work out. 我试过使用group_by,但没有成功。

here's my model: 这是我的模型:

$this->db->where('resto_settings_time.resto_id',$id);
$this->db->select('op_time_start,op_time_end, table_number, table_size');
$this->db->from('resto_settings_time');
$this->db->join('resto_settings_table', 'resto_settings_time.resto_id = resto_settings_table.resto_id', 'left');
$query = $this->db->get();
return $query->result();

my Controller: 我的控制器:

$data['rows'] = $this->process_resto_list->rsrv_details($id);
    $this->load->view('sample',$data);

my view: 我的观点:

foreach ($rows as $row) {
        echo $start= $row->op_time_start . br();
        echo $end= $row->op_time_end . br();
        echo $num = $row->table_number . br();
        echo $size = $row->table_size . br();
    }

And here is what it returns: 这是它返回的内容:

07:00:00 24:00:00 7 3 07:00:00 24:00:00 6 4 07:00:00 24:00:00 7 3 07:00:00 24:00:00 6 4

I would like 07:00:00 24:00:00 to repeat only once.. Please help me out, I'm really confused. 我希望07:00:00 24:00:00仅重复一次。.请帮帮我,我真的很困惑。 Any help will be much appreciated. 任何帮助都感激不尽。 Thank you 谢谢

我没有收到您的问题,但是要删除重复的数据,您必须按查询分组

$this->db->group_by()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM