Postingan lainnya
sort by codeigniter
saya ingin sort data array dengan ketentua city_id yg isinya 1-5 harus tampil duluan dengan penyortiran city_name, dan sisa city_id 6 dan seterusnya juga dengan penyotiran name jugaa.. oh iyaa, city_id dan city_name itu jika di sort ascending beda
- ini model :
function city(){
$this->db->select('city_name, city_id');
$this->db->from('city');
$this->db->where('deleted', '0');
$this->db->order_by('city_id', 'asc');
$query = $this->db->get();
return $query->result_array();
}
- controller
public function index(){
// print_r($this->session->userdata());
// die();
$data = array(
'title' => 'Homepage',
'page' => 'view_home',
'js' => array(
base_url().'assets/js/typehead.js',
base_url().'assets/js/bootstrap-select.min.js',
base_url().'assets/js/jquery.vide.js',
base_url().'assets/plugins/owl/owl.carousel.min.js'
),
'css' => array(
base_url().'assets/css/bootstrap-select.css',
base_url().'assets/plugins/owl/assets/owl.carousel.min.css',
base_url().'assets/plugins/owl/assets/owl.theme.default.min'
),
'categories' => $this->main_model->categories(),
'city' => $this->main_model->city(),
'video_banner' => $this->main_model->video_banner(),
'workspace' => $this->workspace_model->get()
);
// print_r($data['video_banner']);die();
$this->load->view('view_template', $data);
}
- view
<select class="selectpicker show-menu-arrow" name="loc" id="findcity" style="padding: 17px;">
<option value="">Pilih Lokasi</option>
<?php foreach ($city as $ci){ ?>
<option value="<?php echo $ci['city_name']; ?>">
<?php echo $ci['city_name']; ?>
</option>
<?php } ?>
</select>
0
Belum ada Jawaban. Jadi yang pertama Jawaban
Login untuk ikut Jawaban