Something wierd here - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=22) +--- Thread: Something wierd here (/showthread.php?tid=41538) |
Something wierd here - El Forum - 05-10-2011 [eluser]Todlerone[/eluser] Hello everyone and TY in advance. For the life of me I can't figureout why this will not work (I'm sure is sooooo simple...but OMG I think I'm brain dead). This is in a view with some $data. Here is the output of the $plan_fract array. I have used and end() function in the controller to always get the last row in the database so my array will always only contain data like below (ie, one row). Code: Array I'm trying to do this... Code: echo '<pre>'; print_r($plan_fract); echo '</pre>'; I get this as an output... partial=1 partial=N partial= partial= I never get into my if loops, so I added the echo partial to see what it was seeing.... Something wierd here - El Forum - 05-11-2011 [eluser]n0xie[/eluser] What's there to not understand? It loops over each value in your array (see your first code snippet) and echo's that, so you are seeing exactly what you are supposed to see, namely each value inside your array... Hence the output is exactly the same as the content of your array. Any alteration to your values is done after the echo... Something wierd here - El Forum - 05-11-2011 [eluser]Todlerone[/eluser] code]Array ( [plan_fraction_num] => 1 [plan_fraction_partial_fraction] => No [plan_fraction_pct_deli] => [plan_fraction_pct_total] => ) [/code] I'm trying to do this... Code: echo '<pre>'; print_r($plan_fract); echo '</pre>'; TY Something wierd here - El Forum - 05-11-2011 [eluser]n0xie[/eluser] Yeah because when you foreach your array, $pf['plan_fraction_partial_fraction'] doesn't exist since $pf gets assigned the values of your array as shown in the output of your first example. if you want to make your code work do this: Code: echo '<pre>'; print_r($plan_fract); echo '</pre>'; Something wierd here - El Forum - 05-11-2011 [eluser]InsiteFX[/eluser] You need to define your variable before you can use it. In your Controller: Code: public $fract; InsiteFX Something wierd here - El Forum - 05-11-2011 [eluser]Todlerone[/eluser] [quote author="n0xie" date="1305141374"]Yeah because when you foreach your array, $pf['plan_fraction_partial_fraction'] doesn't exist since $pf gets assigned the values of your array as shown in the output of your first example. if you want to make your code work do this: Code: echo '<pre>'; print_r($plan_fract); echo '</pre>'; TY n0xie. That was the trick. Funny though, I haven't had this problem before with passing arrays to my view. I have to work through the reason again for this so that I truely understand it. CHEERS |