CodeIgniter Forums
clear select - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Development (https://forum.codeigniter.com/forumdisplay.php?fid=6)
+--- Forum: CodeIgniter 3.x (https://forum.codeigniter.com/forumdisplay.php?fid=17)
+--- Thread: clear select (/showthread.php?tid=86509)



clear select - futurewebs - 01-28-2023

Hi folks,
Using CI3
is there a way to clear / flush the select array ?

heres a basic example to try and explain better


PHP Code:
$this->db->select('user.*');


if (
$rs_type == 'small_select'){

// clear the select options and start again
 
$this->db->select('user.user_id'); // need to only select single item

 
$query $this->db->get('users');
 
$result $query->result();
 
 } else {

 
// here we select everything as normal

 
$query $this->db->get('users');
 
$result $query->result();

 } 


thanks in advance


RE: clear select - InsiteFX - 01-28-2023

There is a 
PHP Code:
$this->db->reset_query() 



RE: clear select - futurewebs - 01-28-2023

would this not clear the whole query though rather than just the select element ?


RE: clear select - superior - 01-28-2023

(01-28-2023, 06:05 AM)futurewebs Wrote: would this not clear the whole query though rather than just the select element ?

PHP Code:
<?php
// Not tested but i would go for something like this
$select = ( null !== $rs_type && 'small_select' == $rs_type ) ? 'user.user_id' 'user.*';
$query  $this->db->select($select)->get('users');

$result $query->result();