Postingan lainnya
Menampilkan data dari tabel yang berbeda pada ci
Saya ingin menampilkan data dari tabel lain setelah di join. Saya ingin menampilkan data dari tabel usermeta yaitu meta_key. Data yang ditampilkan yaitu meta_value yang meta_keynya adalah st_phone Ini adalah Modelnya
function all_order($date1, $date2, $status) {
if($status == 'all'){
$query = $this->db->query("SELECT ht_users.display_name, ht_users.user_email, ht_usermeta.meta_key, ht_usermeta.meta_value, _order.room_num_search, _order.wc_order_id, _order.total_order, _order.status, ht_posts.post_title, ht_posts.post_date FROM ht_st_order_item_meta AS _order
inner join ht_users on _order.user_id = ht_users.ID
inner join ht_posts on _order.room_id = ht_posts.ID
inner join ht_usermeta on _order.user_id = ht_usermeta.user_id
WHERE
(
(
_order.check_in_timestamp <= UNIX_TIMESTAMP('".$date1."')
AND _order.check_out_timestamp >= UNIX_TIMESTAMP('".$date1."')
)
OR (
_order.check_in_timestamp <= UNIX_TIMESTAMP('".$date2."')
AND _order.check_out_timestamp >= UNIX_TIMESTAMP('".$date2."')
)
OR (
_order.check_in_timestamp <= UNIX_TIMESTAMP('".$date1."')
AND _order.check_out_timestamp >= UNIX_TIMESTAMP('".$date2."')
)
OR (
_order.check_in_timestamp >= UNIX_TIMESTAMP('".$date1."')
AND _order.check_out_timestamp <= UNIX_TIMESTAMP('".$date2."')
)
)");
}elseif($status == 'canceled'){
$query = $this->db->query("SELECT ht_users.display_name, ht_users.user_email, _order.room_num_search, _order.wc_order_id, _order.total_order, _order.status, ht_posts.post_title, ht_posts.post_date FROM ht_st_order_item_meta AS _order
inner join ht_users on _order.user_id = ht_users.ID
inner join ht_posts on _order.room_id = ht_posts.ID
WHERE
(
(
_order.check_in_timestamp <= UNIX_TIMESTAMP('".$date1."')
AND _order.check_out_timestamp >= UNIX_TIMESTAMP('".$date1."')
)
OR (
_order.check_in_timestamp <= UNIX_TIMESTAMP('".$date2."')
AND _order.check_out_timestamp >= UNIX_TIMESTAMP('".$date2."')
)
OR (
_order.check_in_timestamp <= UNIX_TIMESTAMP('".$date1."')
AND _order.check_out_timestamp >= UNIX_TIMESTAMP('".$date2."')
)
OR (
_order.check_in_timestamp >= UNIX_TIMESTAMP('".$date1."')
AND _order.check_out_timestamp <= UNIX_TIMESTAMP('".$date2."')
)
)
AND _order.`status` IN ('cancelled', 'wc-cancelled')");
}elseif ($status == 'complete') {
$query = $this->db->query("SELECT ht_users.display_name, ht_users.user_email, _order.room_num_search, _order.wc_order_id, _order.total_order, _order.status, ht_posts.post_title, ht_posts.post_date FROM ht_st_order_item_meta AS _order
inner join ht_users on _order.user_id = ht_users.ID
inner join ht_posts on _order.room_id = ht_posts.ID
WHERE
(
(
_order.check_in_timestamp <= UNIX_TIMESTAMP('".$date1."')
AND _order.check_out_timestamp >= UNIX_TIMESTAMP('".$date1."')
)
OR (
_order.check_in_timestamp <= UNIX_TIMESTAMP('".$date2."')
AND _order.check_out_timestamp >= UNIX_TIMESTAMP('".$date2."')
)
OR (
_order.check_in_timestamp <= UNIX_TIMESTAMP('".$date1."')
AND _order.check_out_timestamp >= UNIX_TIMESTAMP('".$date2."')
)
OR (
_order.check_in_timestamp >= UNIX_TIMESTAMP('".$date1."')
AND _order.check_out_timestamp <= UNIX_TIMESTAMP('".$date2."')
)
)
AND _order.`status` IN ('complete', 'wc-completed')");
}elseif ($status == 'pending') {
$query = $this->db->query("SELECT ht_users.display_name, ht_users.user_email, _order.room_num_search, _order.wc_order_id, _order.total_order, _order.status, ht_posts.post_title, ht_posts.post_date FROM ht_st_order_item_meta AS _order
inner join ht_users on _order.user_id = ht_users.ID
inner join ht_posts on _order.room_id = ht_posts.ID
WHERE
(
(
_order.check_in_timestamp <= UNIX_TIMESTAMP('".$date1."')
AND _order.check_out_timestamp >= UNIX_TIMESTAMP('".$date1."')
)
OR (
_order.check_in_timestamp <= UNIX_TIMESTAMP('".$date2."')
AND _order.check_out_timestamp >= UNIX_TIMESTAMP('".$date2."')
)
OR (
_order.check_in_timestamp <= UNIX_TIMESTAMP('".$date1."')
AND _order.check_out_timestamp >= UNIX_TIMESTAMP('".$date2."')
)
OR (
_order.check_in_timestamp >= UNIX_TIMESTAMP('".$date1."')
AND _order.check_out_timestamp <= UNIX_TIMESTAMP('".$date2."')
)
)
AND _order.`status` IN ('pending', 'wc-processing')");
}elseif ($status == 'refunded') {
$query = $this->db->query("SELECT ht_users.display_name, ht_users.user_email, _order.room_num_search, _order.wc_order_id, _order.total_order, _order.status, ht_posts.post_title, ht_posts.post_date FROM ht_st_order_item_meta AS _order
inner join ht_users on _order.user_id = ht_users.ID
inner join ht_posts on _order.room_id = ht_posts.ID
WHERE
(
(
_order.check_in_timestamp <= UNIX_TIMESTAMP('".$date1."')
AND _order.check_out_timestamp >= UNIX_TIMESTAMP('".$date1."')
)
OR (
_order.check_in_timestamp <= UNIX_TIMESTAMP('".$date2."')
AND _order.check_out_timestamp >= UNIX_TIMESTAMP('".$date2."')
)
OR (
_order.check_in_timestamp <= UNIX_TIMESTAMP('".$date1."')
AND _order.check_out_timestamp >= UNIX_TIMESTAMP('".$date2."')
)
OR (
_order.check_in_timestamp >= UNIX_TIMESTAMP('".$date1."')
AND _order.check_out_timestamp <= UNIX_TIMESTAMP('".$date2."')
)
)
AND _order.`status` IN ('wc-refunded')");
}elseif ($status == 'incomplete') {
$query = $this->db->query("SELECT ht_users.display_name, ht_users.user_email, _order.room_num_search, _order.wc_order_id, _order.total_order, _order.status, ht_posts.post_title, ht_posts.post_date FROM ht_st_order_item_meta AS _order
inner join ht_users on _order.user_id = ht_users.ID
inner join ht_posts on _order.room_id = ht_posts.ID
WHERE
(
(
_order.check_in_timestamp <= UNIX_TIMESTAMP('".$date1."')
AND _order.check_out_timestamp >= UNIX_TIMESTAMP('".$date1."')
)
OR (
_order.check_in_timestamp <= UNIX_TIMESTAMP('".$date2."')
AND _order.check_out_timestamp >= UNIX_TIMESTAMP('".$date2."')
)
OR (
_order.check_in_timestamp <= UNIX_TIMESTAMP('".$date1."')
AND _order.check_out_timestamp >= UNIX_TIMESTAMP('".$date2."')
)
OR (
_order.check_in_timestamp >= UNIX_TIMESTAMP('".$date1."')
AND _order.check_out_timestamp <= UNIX_TIMESTAMP('".$date2."')
)
)
AND _order.`status` IN ('incomplete')");
}else{
$query = $this->db->query("SELECT ht_users.display_name, ht_users.user_email, _order.room_num_search, _order.wc_order_id, _order.total_order, _order.status, ht_posts.post_title, ht_posts.post_date FROM ht_st_order_item_meta AS _order
inner join ht_users on _order.user_id = ht_users.ID
inner join ht_posts on _order.room_id = ht_posts.ID
WHERE
(
(
_order.check_in_timestamp <= UNIX_TIMESTAMP('".$date1."')
AND _order.check_out_timestamp >= UNIX_TIMESTAMP('".$date1."')
)
OR (
_order.check_in_timestamp <= UNIX_TIMESTAMP('".$date2."')
AND _order.check_out_timestamp >= UNIX_TIMESTAMP('".$date2."')
)
OR (
_order.check_in_timestamp <= UNIX_TIMESTAMP('".$date1."')
AND _order.check_out_timestamp >= UNIX_TIMESTAMP('".$date2."')
)
OR (
_order.check_in_timestamp >= UNIX_TIMESTAMP('".$date1."')
AND _order.check_out_timestamp <= UNIX_TIMESTAMP('".$date2."')
)
)");
}
return $query->result();
}
ini adalah controller
function all_order(){
date_default_timezone_set('Asia/Makassar');
$awal = $this->input->post('begindate');
if($awal == ''){ $awal = date('m/d/Y');}
$awals = DateTime::createFromFormat('m/d/Y',$awal);
$awal = $awals->format("Y-m-d");
$begindate = $awals->format("d-m-Y");
$akhir = $this->input->post('enddate');
if($akhir == ''){ $akhir = date("m/d/Y", strtotime("+1 day"));}
$akhirs = DateTime::createFromFormat('m/d/Y',$akhir);
$akhir = $akhirs->format("Y-m-d");
$enddate = $akhirs->format("d-m-Y");
$data['begindate'] = $begindate;
$data['enddate'] = $enddate;
$data['data'] = $this->M_reservation->all_order($awal, $akhir, $this->input->post('status')) ;
$data['status'] = $this->input->post('status');
$data['st_phone'] = $this->input->post('meta_key');
$this->load->view('Reservation/all_order', $data);
}
dan ini adalah view
foreach($data as $u){
$total = $total + $u->total_order;
?>
<tr class='odd gradeX context'>
<td><a class="btn btn-success btn-xs" href="<?php echo base_url('index.php/Reservation/download_invoice/'); ?>"><span class="fa fa-fw fa-download" ></span> Invoice</a></td>
<td><?php echo $u->wc_order_id ?></td>
<td><?php echo $u->post_date?></td>
<td><?php echo $u->display_name?></td>
<td><?php echo $u->user_email?></td>
<td><?php echo $u->meta_value?></td>
<td></td>
<td><?php echo $u->post_title?></td>
<td><?php echo $u->room_num_search?></td>
<td><?php echo $u->status?></td>
<td align="right"><?php echo number_format($u->total_order); ?></td>
</tr>
0
Belum ada Jawaban. Jadi yang pertama Jawaban
Login untuk ikut Jawaban