CodeIgniter Forums
[Solved]Model Problem - 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: [Solved]Model Problem (/showthread.php?tid=21873)



[Solved]Model Problem - El Forum - 08-23-2009

[eluser]eric cumbee[/eluser]
im not sure what is going on, i am passing an array into my model and loop through it creating or_where statements. the problem i am running into is that if i pass in a value like "Statesboro" when the query is executed the sql statement is something like this

Code:
SELECT COUNT(*) AS `numrows`
FROM (`voters`)
WHERE `reg_city` = 'S'

and then this is my model function
Code:
function count_voter($city) {
        if($city) {
           foreach($city as $row)
           {
                 $this->db->or_where('reg_city',$row['reg_city']);
            }
        }
        $this->db->from('voters');
        $count = $this->db->count_all_results();
        return $count;
    }

i have traced the data flowing all the way back from my view to the controller, and then the data being passed to the model from the controller, so i know for sure that the data is making it through the view and the controller with out being concatenated.


[Solved]Model Problem - El Forum - 08-23-2009

[eluser]tomcode[/eluser]
Probably $row is not an array but a string


[Solved]Model Problem - El Forum - 08-23-2009

[eluser]eric cumbee[/eluser]
just tried wrapping it in an if(is_array($city) and it is an array. so thats not the problem.


[Solved]Model Problem - El Forum - 08-23-2009

[eluser]eric cumbee[/eluser]
never mind i see what you are saying and that was indeed the problem. thank you, could you explain why it passed the first letter of the value rather an a error message.


[Solved]Model Problem - El Forum - 08-23-2009

[eluser]tomcode[/eluser]
I can't really explain it, but I know this kind of effect Smile, I believe one can also retrieve a letter from a string variable by using $string_variable[n].