Cannot test if a field is empty or not - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Cannot test if a field is empty or not (/showthread.php?tid=37890) Pages:
1
2
|
Cannot test if a field is empty or not - El Forum - 01-24-2011 [eluser]caperquy[/eluser] Hello I am implementing an application where I have to test if a field is empty or not. That field is defined within PhpMySQL as follows : Field name : DIVERS Type : varchar(80) Interclassement : latin1_swedish_ci Null : No (non) Defaut : None (aucun) There are cases where nothing has been put into the field. Nevertheless whenever I test that field in the controller using an instruction such as Code: if (empty($DIVERS)) The same occurs if I use is_null Could someone give me a clue ? Thanks in advance. CapErquy Cannot test if a field is empty or not - El Forum - 01-24-2011 [eluser]toopay[/eluser] Can you post the code, which you use to retrieve fields from database. Cannot test if a field is empty or not - El Forum - 01-24-2011 [eluser]caperquy[/eluser] Thanks for answering that fast. In fact I simplified the code when I put my first question on line. The exact code is a little bit more complex since I retrieve other fields as well. The code in the model is as follows ($critere represents the word I am looking for in the database) : Code: [b]function recherche($critere)[/b] The code in the controller is as follows : Code: $data['resultats'] = $this->catalogue_model->recherche($critere)->result(); Obviously when I will get the solution to my problem the echo instructions will be replaced by more sophisticated ones. I hope this will be useful tp you Cannot test if a field is empty or not - El Forum - 01-24-2011 [eluser]toopay[/eluser] I assume, that you are trying to find a single row of data, with specific keywords. First, on your Model change to this Code: function recherche($critere) Code: //I assume, in this stage, that your model class have properly loaded Let me know, if it work for you... Btw, i think maybe next time you should post your question at proper forum, because this is Bug Report section i believe. Cannot test if a field is empty or not - El Forum - 01-24-2011 [eluser]toopay[/eluser] forgot one line...replace above model, with this Code: function recherche($critere) Cannot test if a field is empty or not - El Forum - 01-24-2011 [eluser]caperquy[/eluser] Many thanks for your answer. I will not be able to test it before tomorrow but when done I will let you know. CapErquy Cannot test if a field is empty or not - El Forum - 01-25-2011 [eluser]caperquy[/eluser] I am back to my application. I am trying to implement what you said but I am confused with the instruction Code: return (count($result) >0 ? $result[0] :NULL); If in my controller if I execute the following instructions : Code: $resultats=$this->catalogue_model->recherche($critere, $autrechoix); the array shows only one result (I expect 13) and the number found is not shown. I must be missing something but I do not see what. Caperquy Cannot test if a field is empty or not - El Forum - 01-25-2011 [eluser]caperquy[/eluser] Sorry but forget the parameter $autrechoix which I plan to use in the future. For the time being it is not implemented. I only have : Code: $resultats=$this->catalogue_model->recherche($critere); CapErquy Cannot test if a field is empty or not - El Forum - 01-25-2011 [eluser]toopay[/eluser] like i said, I assume, that you are trying to find a single row of data (not array), with specific keywords. now tell me, are you try to find a list or single row? Cannot test if a field is empty or not - El Forum - 01-25-2011 [eluser]caperquy[/eluser] Yes I am trying to get a list, ie zero or several rows. CapErquy |