doucai5315 2016-05-16 01:57
浏览 42
已采纳

使用连接表进行codeigniter搜索

this is my controller

function search_keyword()
{
    $cari    =   $this->input->GET('cari');
    $data['dapat']    =   $this->order_test_m->search($cari);
    $this->load->view('admin/a',$data);
}

this is my model

    function search($cari)
    {
        $this->db->from("uhd_user_order AS t1");
        $this->db->join("uhd_user_product_order AS t2", "t1.user_order_id = t2.user_order_id");
        $this->db->where('user_order_reference',$cari);
        $query = $this->db->get('uhd_user_order');
        return $query->result();
    }

this is my view

                    <tr>
                        <th>No.</th>
                        <th>Customer Name</th>
                        <th>Product Code</th>
                        <th>Payment Type</th>
                        <th>Delivery Date</th>
                        <th>Total Price</th>
                        <th style="text-align: center;padding-right: 15px;">Action</th>
                    </tr>
            <?php if($dapat !== NULL) { ?>
                <?php foreach ($dapat as $row => $test) {

                    ?>
                    <tr>
                        <td><?= $test->user_order_id?></td>
                        <td><?= $test->sender_name?></td>
                        <td><?= $test->user_product_order_id?></td>
                        <td><?= $test->payment_type ?></td>
                        <td><?= $test->time.$test->date ?></td>
                        <td><?= $test->delivery_price?></td>
                    </tr>
                <?php }
            }else{
                echo "<td colspan='3'>no customer for the result!</td>";

            }
            ?>
        </table>

guys i need help here im new in codeigniter. i need to make a search but the search result are needing 2 table from my database. time, date and user_product_order_id are from the uhd_user_product_order, and user_order_id, sender_name, payment_type, and user_order_reference(this the search key) are from uhd_user_order

in the view i can view it from my table uhd_user_order, but i cant view the time, date and the user_product_order_id

can you help me how to join the 2 table so i can see the best result from the search

  • 写回答

2条回答 默认 最新

  • dpbe81245 2016-05-16 07:28
    关注

    Use this code on your model

    public function search($cari){
    
          $this->db->select('*');
          $this->db->from("uhd_user_order AS t1");
          $this->db->join("uhd_user_product_order AS t2", "t2.user_order_id = t1.user_order_id");  # confirm user_order_id in both table
          $this->db->where('user_order_reference',$cari);
          $query = $this->db->get();
          return $query->result();
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥35 平滑拟合曲线该如何生成
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 自己瞎改改,结果现在又运行不了了
  • ¥15 链式存储应该如何解决
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站