SEARCHING with some condition in codeigniter SEARCHING with some condition in codeigniter codeigniter codeigniter

SEARCHING with some condition in codeigniter


It is normal that you always get the last place because your logic is not correct. First, you have an error in your model. Secondly, you can improve your model code:

function find_user($like){   $this->db->like('name', $like, 'after');   return $this->db->get('user')->result();}

Now, in your controller you want to change the variable place according to the value of place_code. You are allowed to add a new key (or change an existing one) in real time to the stdClass() as follows:

foreach($find as $i => $result){   // By default, we assume the 'place_code' is equal to '1'   $find[$i]->place = 'Secretray';   if($result->place_code == '2')       $find[$i]->place = 'OB';   else       $find[$i]->place = 'Manager';}$data['find'] = $find;$this->load->view('home/search', $data);

Finally, in your view:

 <?php foreach ($find as $result){ ?>    <table>        <thead>            <tr>                <th>ID</th>                <th>Name</th>                <th>Place</th>            </tr>        </thead>        <tbody>            <tr>                <td><?php echo $result->id; ?></td>                <td><?php echo $result->name; ?></td>                <td><?php echo $result->place; ?></td>            </tr>        </tbody>    </table><?php } ?>