UGH! Arrays are giving me a headache :( - 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: UGH! Arrays are giving me a headache :( (/showthread.php?tid=11820) |
UGH! Arrays are giving me a headache :( - El Forum - 09-24-2008 [eluser]Kinsbane[/eluser] So, I have a resultset that outputs this: Code: Array I have my code grab this dataset with an object, and then I try to loop through the object with this: Code: foreach($divisions->result_array() as $row) However, this only gives me the first record in the dataset ([id] of 1). I am trying to loop through this dataset and then give it to the $data[] array and have the values stored show up in the view file. But everything I'm trying won't let me get at the data I need. All I want to do is take that result set and put it into the $data array like this: Code: $data['division'][$key] = $value; But everything I'm trying isn't working - it's leaving me stuck at the first level of arrays, which then contain arrays which get at the values I need. UGH! Arrays are giving me a headache :( - El Forum - 09-24-2008 [eluser]Sumon[/eluser] [quote author="Kinsbane" date="1222299031"] I have my code grab this dataset with an object, and then I try to loop through the object with this: Code: foreach($divisions->result_array() as $row) [/quote] First record in the dataset because die() function stop execution immediately after first print_r($row); statement [quote author="Kinsbane" date="1222299031"] All I want to do is take that result set and put it into the $data array like this: Code: $data['division'][$key] = $value; Try to use: Code: foreach($my_array as $key=>$value) UGH! Arrays are giving me a headache :( - El Forum - 09-24-2008 [eluser]manilodisan[/eluser] Lol...die = die ))) UGH! Arrays are giving me a headache :( - El Forum - 09-24-2008 [eluser]Kinsbane[/eluser] Well, I must say, I am a pretty fart smeller. For a while I didn't know why I was getting the last record in the dataset (id #6), because of the way I was assigning the data to the $data['divisions']. (each loop was replacing the data previously there). I guess at that point I would then need to have $data['divisions'][1], $data['divisions'][2], etc.. UGH! Arrays are giving me a headache :( - El Forum - 09-24-2008 [eluser]Kinsbane[/eluser] [quote author="Kinsbane" date="1222308954"]Well, I must say, I am a pretty fart smeller. For a while I didn't know why I was getting the last record in the dataset (id #6), because of the way I was assigning the data to the $data['divisions']. (each loop was replacing the data previously there). I guess at that point I would then need to have $data['divisions'][1], $data['divisions'][2], etc..[/quote] Yup, that did it: Code: $index = 0; |