Php 如何使用foreach在表中显示具有左联接的select查询记录?

Php 如何使用foreach在表中显示具有左联接的select查询记录?,php,mysql,codeigniter,foreach,left-join,Php,Mysql,Codeigniter,Foreach,Left Join,我有两张桌子(A表和B表)。我需要在一个表中显示它们,但在如何显示表中的记录方面存在问题。请看我的样品: 表A: id name 1 John 2 Mark 3 Nick` 表b: id job 1 Encoder 2 3 Programmer` 我做了一个查询来连接这两个表 select a.id, a.name, b.job from table_a a left join table_b b on b.id=a.id order by a.i

我有两张桌子(A表和B表)。我需要在一个表中显示它们,但在如何显示表中的记录方面存在问题。请看我的样品:

表A:

id   name
1    John
2    Mark
3    Nick`
表b:

id     job 
1    Encoder
2
3    Programmer`
我做了一个查询来连接这两个表

select a.id, a.name, b.job from table_a a
left join table_b b on b.id=a.id
order by a.id;
使用codeigniter

这是控制器:

$this->db->select('a.id, a.name, b.job);
$this->db->from('table a');
$this->db->join('table b', 'b.id=a.id', 'left');
$this->db->order_by('a.id');
$query = $this->db->get();
$data["view_records"]=$query;
$this->load->view("table_name", $query);
这就是观点

<table id="tablestyle" class="table table-bordered table-hover table-condensed">
    <col width="50">
    <col width="150">
    <col width="150">
    <col width="150">
    <thead>
        <tr>
            <th><strong>ID</strong></th>
            <th><strong>NAME</strong></th>
            <th><strong>JOB</strong></th>
            <th></th>
        </tr>
    </thead>
    <tbody>
        <?php foreach($view_records->result() as $row) {  ?>
                <tr>
                    <td><?php echo $row->a.id; ?></td>
                    <td><?php echo $row->a.name; ?></td>
                    <td><?php echo $row->b.job; ?></td>
                    <td><input type="submit" value="Modify" id="btnModify" class="btn btn-block btn-success btn-xs" onclick="btnModify('<?php echo $row->a.id; ?>');"/></td>
                </tr>
        <?php } ?>
    </tbody>
</table>

ID
名称
工作

在型号中

public function get_user()
{
    $query = $this->db->query("select a.id, a.name, b.job from table_a a
        left join table_b b on b.id=a.id
        order by a.id");
    $result = $query->result_array();
    return $result;
}
在控制器中

$data['get_user'] = $this->model_name->get_user();

$this->load->view("view_name", $data);
在视图中

<table id="tablestyle" class="table table-bordered table-hover table-condensed">
    <col width="50">
    <col width="150">
    <col width="150">
    <col width="150">
    <thead>
        <tr>
            <th><strong>ID</strong></th>
            <th><strong>NAME</strong></th>
            <th><strong>JOB</strong></th>
            <th></th>
        </tr>
    </thead>
    <tbody>
        <?php foreach($get_user as $rowItem) {  ?>
                <tr>
                    <td><?php echo $rowItem['a.id'] ?></td>
                    <td><?php echo $rowItem['a.name'] ?></td>
                    <td><?php echo $rowItem['b.job'] ?></td>
                    <td><input type="submit" value="Modify" id="btnModify" class="btn btn-block btn-success btn-xs" onclick="btnModify('<?php echo $rowItem['a.id'] ?>');"/></td>
                </tr>
        <?php } ?>
    </tbody>
</table>

ID
名称
工作