I am using CodeIgniter and I am facing the problem with join method.
I want services from db_services
table by service_id which is also stored in db_orders
within the same column name service_id
, I have service_id
as a primary key in db_services
table.
Now user add services by clicking the checkbox of the required services with the help of implode()
function which puts the data correctly into database db_orders
table under service_id
column i.e. 1,2,3,5
Now when I retrieve data from db_orders
I get comma-separated value from the database which works fine when I remove this line $this->db->join( $this->db->dbprefix('db_services'), $this->db->dbprefix('db_services').'.service_id = '.$this->db->dbprefix('db_orders').'.service_id' );
within my Order_model -> view_orders() function everything works like a charm but when I add that line it only show one record (first record) for instance if two (2) service_id are inserted so I get only the one which I guess the first number which is inserted during the database.
<?php $services = explode(",", $value->service_id);
foreach ( $services as $service ): ?>
<a href="" class="btn btn-success btn-flat btn-xs"><?php echo $service; ?></a>
<?php endforeach; ?>
That was the problem I have solved but the actual problem is when I use join
table method it does not work let me copy-paste my code which helps you to better under the problem well I have mentioned every little details if you need more I can elaborate further.
Order_model -> view_orders()
<?php
public function view_orders()
{
$this->db->select( '*' );
$this->db->from( $this->db->dbprefix('db_orders') );
$this->db->join( $this->db->dbprefix('db_order_status'), $this->db->dbprefix('db_order_status').'.order_status_id = '.$this->db->dbprefix('db_orders').'.order_status_id' );
$this->db->join( $this->db->dbprefix('db_users'), $this->db->dbprefix('db_users').'.user_id = '.$this->db->dbprefix('db_orders').'.user_id' );
$this->db->join( $this->db->dbprefix('db_services'), $this->db->dbprefix('db_services').'.service_id = '.$this->db->dbprefix('db_orders').'.service_id' );
$query = $this->db->get();
return $query->result();
}
?>
Order Controller -> index()
public function index()
{
$data['orders'] = $this->order->view_orders();
$data['title'] = "View All Orders";
$this->load->template('orders/view_all_orders', $data);
}
orders/view_all_orders.php
<?php
$services = explode(",", $value->service_id);
foreach ( $services as $service ): ?>
<a href="" class="btn btn-success btn-flat btn-xs"><?php echo $service; ?></a>
<?php endforeach; ?>