gpt4 book ai didi

php - 如何使用 codeigniter 在单个 View 页面中维护两个表数据

转载 作者:搜寻专家 更新时间:2023-10-31 21:22:01 24 4
gpt4 key购买 nike

[![enter image description here][1]][1][enter image description here][2]我有两个表 invoice 和 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

这是我的 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);
}

}

我的模型是:-

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

中的不止一种产品描述

我正在尝试我的 View 页面是

发票编号:-123姓名:-xyzx

产品价格数量阿斯达夫 12 10阿萨夫萨 12 13

最佳答案

在 Controller 中

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

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

关于php - 如何使用 codeigniter 在单个 View 页面中维护两个表数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45435682/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com