- Seme Framework
- versi 4.0.3 (ID)
- Persyaratan
- Download & Install
- Pengaturan
- Tutorial
- Perutean URI
- Konstanta
- Variabel Global
- Model
- View
- Controller
- Library
- CLI (command line interface)
- Core
Metode Union Select
Metode union_select
berguna untuk melakukan pertinah SQL SELECT
pada Union Query Buffer.
Bentuk Umum
Berikut ini adalah bentuk umum metode union_select
dari properti $db
yang ada di kelas SENE_Model
.
$this->db->union_select(string $col_name [, string $alias]): $this->db
Parameter
Metode ini terdiri dari 1 parameter wajib dan 1 parameter opsional.
$col_name
Nilai $col_name
dapat berupa nama kolom dan fungsi database.
$alias
Nilai $alias
dapat berupa string untuk pengaliasan kolom.
Contoh
Berikut adalah implementasi kode sumber dari metode union_order_by
di kelas model.
<?php
class Blog_Model extends SENE_Model{
var $tbl = 'd_blog';
var $tbl_as = 'b';
public function __construct(){
parent::__construct();
$this->db->from($this->tbl,$this->tbl_as);
}
public function searchByScore($keyword){
$this->db->union_flush();
//1st union
$this->db->select('id');
$this->db->select('title');
$this->db->select('excerpt');
$this->db->select('date_modified');
$this->db->select_as("3",'score');
$this->db->from($this->tbl,$this->tbl_as);
$this->db->where('title',$keyword,'or','like',1,0);
$this->db->where('excerpt',$keyword,'or','like',0,1);
$this->db->union_create();
//2nd union
$this->db->select('id');
$this->db->select('title');
$this->db->select('excerpt');
$this->db->select('date_modified');
$this->db->select_as("2",'score');
$this->db->from($this->tbl,$this->tbl_as);
$this->db->where('title',$keyword,'or','like%',1,0);
$this->db->where('excerpt',$keyword,'or','like%',0,1);
$this->db->union_create();
//3rd union
$this->db->select('id');
$this->db->select('title');
$this->db->select('excerpt');
$this->db->select('date_modified');
$this->db->select_as("1",'score');
$this->db->from($this->tbl,$this->tbl_as);
$this->db->where('title',$keyword,'or','%like',1,0);
$this->db->where('excerpt',$keyword,'or','%like',0,1);
$this->db->union_create();
//4th union
$this->db->select('id');
$this->db->select('title');
$this->db->select('excerpt');
$this->db->select('date_modified');
$this->db->select_as("0",'score');
$this->db->from($this->tbl,$this->tbl_as);
$this->db->where('title',$keyword,'or','%like%',1,0);
$this->db->where('excerpt',$keyword,'or','%like%',0,1);
$this->db->union_create();
$this->db->union_select('id,title,date_modified,score','score');
$this->db->union_group_by('id');
$this->db->union_order_by('score','desc')->union_limit(1, 14);
return $this->db->union_get();
}
}