如何使用codeigniter

时间:2017-08-01 10:44:04

标签: php codeigniter

[![在此输入图片说明] [1]] [1] [在此输入图片说明] [2]我有两张桌子发票和invoice_description,列invoice_no对于两张桌子都是通用的,我想要从invoice表名,地址,invoice_no和下一个表invoice_description中获取数据我想获取产品描述,数量,价格等。
这是我的表结构

                        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

这是我的控制器: -

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);
    }

}

我的模特是: -

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();    
}   

我想要invoice表中的发票号,姓名和地址     以及invoice_description

中的多个产品说明

我正在尝试查看页面

invoice_no:-123 名:-xyzx

产品价格数量 asdaf 12 10 asafsa 12 13

5 个答案:

答案 0 :(得分:1)

在控制器中

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

在模型中

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;
}   

在视图中

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'];
    } 
}

答案 1 :(得分:0)

在控制器

//Assign empty array $data and assign a results to the respective array
$data['invoice_description_data']= $this->useradmin->selectdealer($id);
$data['invoice_data'] = $this->useradmin->selectdealer1($id); 
$this->load->view('envoice',$data);     

在视图中

//call 
print_r($invoice_data);
print_r($invoice_description_data);

答案 2 :(得分:0)

public function selectdealer($invoice_id) {
    $this->db->select('invoice.*, invoice_description.*')
                 ->from('invoice')
                 ->join('invoice_description', 'invoice.invoice_no = invoice_description.invoice_no');
    ->where ( "invoice.invoice_no='".$invoice_id."' ",'',FALSE );
    $query=$this->db->get();
    return $query->result();
}

使用join从两个表中检索数据

foreach($row as $invoicedata){   
    display your data here
}

答案 3 :(得分:0)

  public function selectdealer($id)  
  {           
     if(!empty($id))
     {
     $this->db->where('invoice_no', $id);
     $query = $this->db->get('invoice');
     return $query->result();     
     }
  }   

这项工作正确用于发票名称 但是这一行的错误

$query = $this->db->get_where('invoice_description', array('invoice_no' => $row['invoice_no']))->result_array();
print_r($query);

答案 4 :(得分:0)

   public function selectdealer($id)  
    {  
     if(!empty($id))
         {
    $this->db->where('invoice_no', $id);
    $query = $this->db->get('invoice');
    return $query->result();  
         }
    }   
   public function selectdealer1($id)  
     {  

     if(!empty($id))
        {
            $this->db->where('invoice_no', $id);
         $query = $this->db->get('invoice_description');  
        return $query->result();  
     }  
  } 

那些功能对我来说正确的感谢朋友aap logo ko mare help karne kaye liye