Panggil saja where()
dalam pernyataan if, sebelum memanggil get()
.
$this->db->select('name');
if(isset($name))
{
//add where clause here, to select specific name
$this->db->where('name', $name);
}
$query = $this->db->get('user');
$result_array = $query->result_array();
Dokumentasi:
https://www.codeigniter.com/user-guide/database/active_record .html