Skip to main content

Sistem Search pada CI

July 13, 2011 by ryudoking

ryudoking's picture

Sesepuh sekalian tanya dunk.. saya kan mau bikin search di web tapi kok error mulu ya gan...

class M_welcome extends Model {
 
	function tampil()
	{
	//$this->db->from('mahasiswa');
	$query = $this->db->get('pegawai'); 
	return $query->result();
 
	}
 
	function caridata()
	{
	$c = $this->input->POST('cari');
	$tipe = $this->input->post('tipe');
 
	$this->db->like($tipe, $c);--->yang ini katanya error
	$query= $this->db->get('pegawai'); 
	return $query->result();
 
	}
 
}

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

like() pada CI

July 13, 2011 by ekopackerjozz, 2 days 6 hours ago
Comment: 8566

ekopackerjozz's picture

Untuk menggunakan sitaks like() aturanya sebagai berikut:

$this->db->like('nama_kolom', 'katakunci');
// Menghasilkan: WHERE nama_kolom LIKE '%katakunci%'

Koding anda:
$c = $this->input->POST('cari');
$tipe = $this->input->post('tipe');
$this->db->like($tipe, $c);
seharusnya:
$this->db->like('cari', $c);
$this->db->like('tipe', $tipe');
//karena $c dan $cari merupakan katakunci hasil dari post

bls:

July 13, 2011 by syabac, 1 day 13 hours ago
Comment: 8577

syabac's picture

dan juga seharusnya:

$c = $this->input->post('cari');

bls jg:

July 13, 2011 by ekopackerjozz, 1 day 12 hours ago
Comment: 8581

ekopackerjozz's picture

iya mas, tapi masi kurang..
seharusnya juga:
$c = $this->input->post('cari');
$tipe = $this->input->post('tipe');
$this->db->like('cari', $c);
$this->db->like('tipe', $tipe');

hehehe..

gw tambahin lagi... $c =

July 14, 2011 by predhtz, 1 day 9 hours ago
Comment: 8586

predhtz's picture

gw tambahin lagi...

$c = $this->input->post("cari");
$tipe = $this->input->post("tipe");
// kalau mau pale where cari LIKE '%$cari%' AND tipe LIKE '%$tipe%'
$this->db->like(array("cari" => $cari, "tipe" => $tipe));

// atau kalau mau pake where cari LIKE '%$cari%' OR tipe LIKE '%$tipe%'

$this->db->like('cari', $c);
$this->db->or_like('tipe', $tipe');

Premium Drupal Themes by Adaptivethemes