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条)

报告相同问题?

悬赏问题

  • ¥15 基于作物生长模型下,有限水资源的最大化粮食产量的资源优化模型建立
  • ¥20 关于变压器的具体案例分析
  • ¥15 生成的QRCode圖片加上下載按鈕
  • ¥15 板材切割优化算法,数学建模,python,lingo
  • ¥15 科来模拟ARP欺骗困惑求解
  • ¥100 iOS开发关于快捷指令截屏后如何将截屏(或从截屏中提取出的文本)回传给本应用并打开指定页面
  • ¥15 unity连接Sqlserver
  • ¥15 图中这种约束条件lingo该怎么表示出来
  • ¥15 VSCode里的Prettier如何实现等式赋值后的对齐效果?
  • ¥20 keepalive配置业务服务双机单活的方法。业务服务一定是要双机单活的方式