![]() |
Why is foreach not working? - 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: Why is foreach not working? (/showthread.php?tid=53977) Pages:
1
2
|
Why is foreach not working? - El Forum - 08-16-2012 [eluser]Kraig[/eluser] Do you have any idea why this foreach would not work? If I just echo $this->variable it displays the last index only..however I want to display it all, but I get an error 'Message: Invalid argument supplied for foreach()' Code: $var = $this->variable; //$this->variable is a global array and it does work Why is foreach not working? - El Forum - 08-16-2012 [eluser]Aken[/eluser] Well if you're echoing $this->variable and it's not showing an array, then it can't be used in a foreach(). Use var_dump() to see what it actually is, and figure out why it's not what you expect. Why is foreach not working? - El Forum - 08-16-2012 [eluser]Kraig[/eluser] I did that and this is what I get: Code: string(10) "7-mini.jpg" I tested it out with the following array and it worked fine, so it's something with my variable Code: $x=array("one","two","three"); Here's how I declare it: Code: public $variable; Why is foreach not working? - El Forum - 08-16-2012 [eluser]Aken[/eluser] Well if you know where it's declared, figure out why that function is not returning an array! Why is foreach not working? - El Forum - 08-16-2012 [eluser]Kraig[/eluser] I've been messing around with this for awhile now...could it be something with my query results? Code: function get_files() Why is foreach not working? - El Forum - 08-16-2012 [eluser]xtremer360[/eluser] That's probably because all you need to do is return $val you do not need this: Code: $test =""; Should be: Code: ... Why is foreach not working? - El Forum - 08-16-2012 [eluser]Kraig[/eluser] When I do this: Code: foreach ($test_var as $value) Model: Code: function get_files() It only shows one result...there's more than one row that this query should return. Why is foreach not working? - El Forum - 08-16-2012 [eluser]Kraig[/eluser] Got it, changed it to result_array(). Thanks everyone!!! Why is foreach not working? - El Forum - 08-16-2012 [eluser]xtremer360[/eluser] Ah snap my bad. Yeah it should have been result_array(). Good luck. Why is foreach not working? - El Forum - 08-16-2012 [eluser]vitoco[/eluser] row_array() returns only 1 row, use result_array() instead Code: function get_files() |