How to keep two data tables on one view page using 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 to both tables, I want to get data from invoice
table name, address, invoice_no and following table invoice_description
I want to get product description, quantity, price, etc.
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: -
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, invoice name and address from table invoice
and more than one product description from tableinvoice_description
I am trying to view a view page
invoice_no: -123 Name: -xyzx
product price asdaf 12 10 asafsa 12 13
source to share
In the controller
public function invoice($id)
{
$this->load->database();
$this->load->model('useradmin');
$data['dealer'] = $this->useradmin->selectdealer($id);
$this->load->view('envoice',$data);
}
In the 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 sight
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'];
}
}
source to share
In the controller
//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);
In view
//call
print_r($invoice_data);
print_r($invoice_description_data);
source to share
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();
}
use a join to retrieve data from two tables
foreach($row as $invoicedata){
display your data here
}
source to share
public function selectdealer($id)
{
if(!empty($id))
{
$this->db->where('invoice_no', $id);
$query = $this->db->get('invoice');
return $query->result();
}
}
this work for the account name is correct but the error is on this line
$query = $this->db->get_where('invoice_description', array('invoice_no' => $row['invoice_no']))->result_array();
print_r($query);
source to share
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();
}
}
this function works for me correctly, thanks friends aap logo ko mare help karne kaye liye
source to share