douba8048 2017-08-01 10:44
浏览 50
已采纳

如何使用codeigniter在单个视图页面中维护两个表数据

[![enter image description here][1]][1][enter image description here][2]I have two tables invoice and invoice_description, The column invoice_no is common for both tables, I want to fetch the data from invoice table name,address,invoice_no and next table invoice_description I want to fetch product description, quantity, price and more.
this is my table structure

                        invoice
         --------------------------------------
          name   bill_no   invoice_no   address    price
           adi     1        2           adasdasd     12
           abc     2        3           adasdas       13


                       invoice_description
        -----------------------------------------------------
               product   invoice_no  quantity 
                a          2          1
                b          2          2
                c          3          3

     i wana output like when i pass invoice_no 2
               invoice_no:-2     name- adi
                product          quantity
                 a                 1
                 b                 2

This is my controller:-

public function invoice($id)
{
            //echo $id;
        $this->load->database();  
             //load the model  
        $this->load->model('useradmin');  
            //$invoice=$this->useradmin->selectdealer($id);  
            //$invoicedes=$this->useradmin->selectdealer1($id);  
            //$data['invoice']=$invoice;
            //$data['invoicedes']=$invoicedes;
            //$this->load->view('envoice',$data);  
          //
        $query = $this->useradmin->selectdealer($id);
        $ids = $this->useradmin->selectdealer1($id);  
        $data['dealers'] =  $query;
        $data['id'] = $ids;                     
        $this->load->view('envoice',$data);
    }

}

My model is:-

public function selectdealer($id)  
{  
    //data is retrive from this query  
    //echo $id;           
    //$this->db->select('*');  
    //$this->db-from('invoice_description');
    $this->db->where('invoice_no', $id);
    $query = $this->db->get('invoice_description');
    return $query->result();
}   
public function selectdealer1($id)  
{  
    //data is retrive from this query  
    //echo $id;
    $query = $this->db->get('invoice');  
    $this->db->where('invoice_no', $id);
    return $query->result();    
}   

I want invoice no, name, and address from invoice table and more than one product description from invoice_description table

I m trying my view page is

invoice_no :-123 name:-xyzx

product des price quantity asdaf 12 10 asafsa 12 13

  • 写回答

5条回答 默认 最新

  • dopnpoh056622 2017-08-01 11:15
    关注

    In controller

    public function invoice($id)
    {
        $this->load->database();  
        $this->load->model('useradmin');  
        $data['dealer'] = $this->useradmin->selectdealer($id);
        $this->load->view('envoice',$data);
    }
    

    In model

    public function selectdealer($id)  
    {  
        $this->db->select("name, address, invoice_no");
        $this->db->from('invoice');
        $this->db->where('invoice_no', $id);
        $result = $this->db->get()->row_array();
        return $result;
    }   
    

    In view

    foreach($dealer as $row){
        echo $row['name'];
        echo $row['address'];
    
            $query = $this->db->get_where('invoice_description', array('invoice_no' => $row['invoice_no']));
    $results = $query->result_array();
    print_r($results);
        foreach($results as $desc){
            echo $desc['quantity'];
            echo $desc['price'];
            echo $desc['desc'];
        } 
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 matlab提取运动物体的坐标
  • ¥15 人大金仓下载,有人知道怎么解决吗
  • ¥15 一个小问题,本人刚入门,哪位可以help
  • ¥15 python安卓开发
  • ¥15 使用R语言GD包一直不出结果
  • ¥15 计算机微处理器与接口技术相关问题,求解答图片的这个问题,有多少个端口,端口地址和解答问题的方法和思路,不要AI作答
  • ¥15 如何根据一个截图编写对应的HTML代码
  • ¥15 stm32标准库的PID角度环
  • ¥15 ADS已经下载好了,但是DAS下载不了,一直显示这两种情况,有什么办法吗,非常急!
  • ¥100 Excel 点击发送自动跳转outlook邮件