![]() |
Help needed with Array. - 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: Help needed with Array. (/showthread.php?tid=14848) Pages:
1
2
|
Help needed with Array. - El Forum - 01-17-2009 [eluser]Solarpitch[/eluser] Hey Guys, I'm having a problem trying to print the value of the arrays being called in the view. Here is my M, V and C. MODEL~~~ Code: //return the display specs CONTROLLER~~~ Code: function compare() VIEW~~~ Code: <?php foreach($in_c_display as $display) Help needed with Array. - El Forum - 01-17-2009 [eluser]JoostV[/eluser] Have you checked if the queries return any records? In your controller, add this just before $this->load->view('pages/compare', $data); Code: echo '<h1>Query results</h1>'; Help needed with Array. - El Forum - 01-17-2009 [eluser]Sarfaraz Momin[/eluser] there seems to be one small issue with your controller method. Your resultset itself is an array and you are making another array to store before you pass it to the view. But in the view the display isn't picking it from the right array level. What I mean here is you are passing the value of this $data['in_c_display'][] to the view which is ok but in the view you are simply not using the correct method to display it. What you can do is try print_r($in_c_display) in your view to identify your array depth and use them to display accordingly. Hope that makes sense. -Sarfaraz. Help needed with Array. - El Forum - 01-18-2009 [eluser]Solarpitch[/eluser] Hey, I done print_r($in_c_display); and it printed out the below. So there are records being returned. Not sure what way I can pick the results out from the array to display on the page. $display->type; etc doesnt seem to work. Code: Array ( [0] => Array ( [0] => Array ( [id] => 1 [phone_id] => 1 [type] => TFT [colours] => 256k [resolution] => 240 x 320 pixel [size] => 2.2" diagonal ) ) [1] => Array ( [0] => Array ( [id] => 2 [phone_id] => 2 [type] => TFT [colours] => 125k [resolution] => 240 x 320 pixel [size] => 2" diagonal ) ) [2] => Array ( [0] => Array ( [id] => 3 [phone_id] => 3 [type] => TPT [colours] => 256k [resolution] => 240 x 320 pixel [size] => 2.8" diagonal ) ) ) Help needed with Array. - El Forum - 01-18-2009 [eluser]Sarfaraz Momin[/eluser] If you check your result closely you would see that there are 2 arrays before it actually populates the result. I have just formatted it to understand better Code: Array ( I can see just one row per id. In that case you can use row_array in your model to just get one single row. In case you still want to use result_array to pull multiple items you would have to either use proper index to create a foreach loop as you did for the base array Code: <?php foreach($in_c_display as $display) Have a good day !!! Help needed with Array. - El Forum - 01-18-2009 [eluser]Solarpitch[/eluser] Man thanks a mill for the help! I should have formatted that myself for you, sorry! It's working perfect now. ![]() Help needed with Array. - El Forum - 01-18-2009 [eluser]John_Betong[/eluser] Here is a formatting function that I use extensively instead of using print_r( $myArray ): Code: //========================================================================== Help needed with Array. - El Forum - 03-11-2009 [eluser]gscharlemann[/eluser] The array formatting code is fantastic...a huge help. But after following the example here, I'm still having issues in my view. I am getting an undefined variable error. I'm attempting to pass $query->result_array() to my view with the following data. In the controller: Code: $people_array = $query->result_array(); The data in the array is as follows: Code: $msg_name not passedArray In the view, I've attempted the following: Code: <?php I get two errors total: A PHP Error was encountered Severity: Notice Message: Undefined variable: contacts_array ... A PHP Error was encountered Severity: Warning Message: Invalid argument supplied for foreach() Any ideas where I went wrong? Help needed with Array. - El Forum - 03-11-2009 [eluser]TheFuzzy0ne[/eluser] Try: Code: <?php foreach($people_array as $person): ?> The problem is that you're trying to go too deep into the array. You're trying to go to level 3 when it's only 2 levels deep. Help needed with Array. - El Forum - 03-11-2009 [eluser]gscharlemann[/eluser] Thanks for looking at my problem. I tried as you suggested, but it didn't work. I'm getting the same two errors. Any other thoughts? |