Reputation: 262
I fetched the product names from first table. and i want to show which company has this product when i clicked the product names . Show those company list form table 2 in Codeigniter. I don't know how to do this, any suggestion regarding this will also be appreciate me. Or this is possible or not in codeigniter ? The way i am doing is right or wrong?
Controller
Here i am getting product names from database
function index() {
$data['items_data'] = $this->Visa_mdl->get_items_name();
$this->load->view('include/header');
$this->load->view('visa/visa',$data);
$this->load->view('include/footer');
}
Here i am trying to do when user click to product name . in the next page only show the company lists which company contain that product.
Models
function get_items_name() {
$this->db->select('*');
$query = $this->get_table1();
return $query->result();
}
function get_items_company_list($id) {
$query = $this->db->query('select company_details.company_name, company_details.address, company_details.contact_number from tbl_product right join company_details on tbl_product.item_id = company_details.item_id where tbl_product.item_id = "$id"');
return $query->result();
}
views Here i am showing the product names
<?php
$data = "";
foreach($items_data as $row){
$data .= '<li class="list-group-item">
<span class="fa fa-angle-double-right pull-right" style=""><p class="pull-left">'.$row->item_id.'</p></span>
<a href="'.base_url("Hotels/visa_dashboard").'">'.$row->item_name.'<span class="fa fa-angle-double-right pull-right" style=""></span>
</a>
</li>';
}
echo $data;
?>
In the next page how can i get company lists.
<?php
foreach($items_company_data as $row) {
echo $row->company_name;
echo $row->contact_number;
echo $row->address;
}
?>
Upvotes: 1
Views: 49
Reputation: 325
Considering that you want to display the company list in this URL Hotels/visa_dashboard, then you need to pass the item id as query string or add this as parameter in your method.
Example in Views
<?php
$data = "";
foreach($items_data as $row){
$data .= '<li class="list-group-item">
<span class="fa fa-angle-double-right pull-right" style=""><p class="pull-left">'.$row->item_id.'</p></span>
<a href="'.base_url("Hotels/visa_dashboard/".$row->item_id).'">'.$row->item_name.'<span class="fa fa-angle-double-right pull-right" style=""></span>
</a>
</li>';
}
echo $data;
?>
And in your function
public function visa_dashboard($item_id){
//get the query
$result = $yourmodel->get_items_company_list($item_id);
$data['company_list'] = $result;
$this->load->view(YOUR_TEMPLATE/company_view.php,$data);
}
And in the company_view.php
foreach($items_company_data as $row) {
echo $row->company_name;
echo $row->contact_number;
echo $row->address;
}
Upvotes: 1