CodeIgniter Forums
simple question about select .. where - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: simple question about select .. where (/showthread.php?tid=73683)



simple question about select .. where - Sarog - 05-22-2019

Good day!

This is my table 'test'

CREATE TABLE `test` (
 `id` int(11) NOT NULL AUTO_INCREMENT,
 `n` varchar(100) NOT NULL,
 PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=22 DEFAULT CHARSET=utf8

id | n
2 | 2
3 | 123

This is my code
 
PHP Code:
       $query $this->db->select('*')->where('id',$id)->get('test');
 
       return $query->result_array(); 


This is result

id = '3'

array(1) {
 [0]=>
 array(2) {
   ["id"]=>
   string(1) "3"
   ["n"]=>
   string(3) "123"
 }
}

id = '3r'
array(1) {
 [0]=>
 array(2) {
   ["id"]=>
   string(1) "3"
   ["n"]=>
   string(3) "123"
 }
}


Why? Whe not empty or error? Thank you


RE: simple question about select .. where - php_rocs - 05-22-2019

@Sarog,

Why you are receiving a record: https://stackoverflow.com/questions/16786063/mysql-comparison-of-integer-value-and-string-field-with-index
Try this: http://sqlfiddle.com/#!9/101556/5

Echo out the executed SQL statement so we can see exactly what is being sent to the database.