Welcome Guest, Not a member yet? Register   Sign In
[Solved]Model Problem
#1

[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.
#2

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

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

[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.
#5

[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].




Theme © iAndrew 2016 - Forum software by © MyBB