Welcome Guest, Not a member yet? Register   Sign In
Problem retrieving database records where a specific text field is empty
#1

[eluser]caperquy[/eluser]
Hello
I have a database from which I want to extract the people for whom nothing has been entered in a field named "deces".
If I run the following request directly within MySQL :
Code:
SELECT * FROM `personnes` WHERE `branche` = 'M' and `deces` = ""
the requested people are successfully retrieved.
On the other hand if I run the same request within my Codeigniter application
Code:
$this->db->select('*');
$this->db->from('personnes');
$this->db->where('branche', 'M');
$this->db->where('deces =', "");
I get people having empty and non empty deces fields.
Is there another way to build such request within Codeigniter ?
Many thanks for help.
Caperquy
#2

[eluser]PhilTem[/eluser]
http://forums.digitalpoint.com/showthread.php?t=29204

Code:
SELECT * FROM table_name WHERE !(ISNULL([columnname]));

OR

Code:
SELECT * FROM table_name WHERE LENGTH(columnname) = 0

(though I haven't tried the second suggestion).
#3

[eluser]CroNiX[/eluser]
You might try manually setting the whole where statement on that line instead of using the 2nd parameter for the value
Code:
$this->db->where('deces = ""');  //two double quotes followed by a single quote
#4

[eluser]caperquy[/eluser]
Many thanks for help. I tried what you said and this time it works.
Regards
Caperquy




Theme © iAndrew 2016 - Forum software by © MyBB