![]() |
[RESOLVED] 'Array to string conversion' error when using query to obtain dropdown list values from database. - 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: [RESOLVED] 'Array to string conversion' error when using query to obtain dropdown list values from database. (/showthread.php?tid=31519) |
[RESOLVED] 'Array to string conversion' error when using query to obtain dropdown list values from database. - El Forum - 06-22-2010 [eluser]Tim in Tulsa[/eluser] Hello, all! I'm new to CodeIgniter and hope you can give me some suggestions on this problem. In my model, I have a function called getDomainList that simply takes a table name and retrieves the database keys and values from a domain table (table with lookup values) and assigns them to an array of key-value pairs. The function works fine and a print_r() statement in the function shows appropriate values before returning the array. For example: Code: Array ( [1] => Preschool [2] => Ages 1 - 3 [3] => Ages 4 - 5 [4] => Kindergarten [5] => 1st - 2nd Grade [6] => 3rd - 4th Grade [23] => 5th Grade [8] => Junior High/Middle School [9] => High School [10] => Adult ) However, when I call this function from my controller to assign the list of values to my $data array (e.g., $data['ages_grades_list'] = $this->workroom_model->getDomainList('ages_grades');), I get the error: Code: A PHP Error was encountered I can't figure out why this is happening and I don't understand why PHP would be trying to do an implicit cast to a string. Thanks for any help/advice that you can provide. Tim [RESOLVED] 'Array to string conversion' error when using query to obtain dropdown list values from database. - El Forum - 06-22-2010 [eluser]adamfairholm[/eluser] Hey Tim, Could we see the getDomainList() function? Adam [RESOLVED] 'Array to string conversion' error when using query to obtain dropdown list values from database. - El Forum - 06-23-2010 [eluser]Tim in Tulsa[/eluser] Thanks, Adam! Yes... Here's the getDomainList() function in the model: Code: function getDomainList($table_name = '') As I mentioned in the original post, print_r($domain_list) is just here for debugging purposes (so that I can see that the array is properly formed). Thanks for any suggestions/ideas. If there's a better way to do this, I'd appreciate your recommendation. Tim [RESOLVED] 'Array to string conversion' error when using query to obtain dropdown list values from database. - El Forum - 06-23-2010 [eluser]Tim in Tulsa[/eluser] OK... I figured this out. The "issue" with the getDomainList() function turned out to be a red herring. It turns out that the problem was in my controller implementation. I used .= to try to "add" information to the $data array. Obviously, this caused the implicit cast of $data from an array to a string. Here's the code that I had: Code: $data = $this->workroom_model->commonLayout(); I corrected the code as follows and voila everything fine: Code: $data = $this->workroom_model->commonLayout(); I guess this is just another newbie mistake! :-) Tim |