variables in if statement - 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: variables in if statement (/showthread.php?tid=52468) |
variables in if statement - El Forum - 06-12-2012 [eluser]brian88[/eluser] I am using a variable in a if statement and it is not recognizing it as a normal variable. Just gives me an error saying unknown variable $i. any ideas? Code: <?php for ($i=1; $i<=$num_of_images ; $i++): ?> heres the full code controller Code: $data['images'] = $this->main_mod->getImages(); view Code: <?php foreach($images as $img): ?> variables in if statement - El Forum - 06-12-2012 [eluser]PhilTem[/eluser] I'm not sure if this solves your problem, but it will at least narrow down where to look for: Code: <?php if( $img->{image.$i} != 'nopic.jpg' ): ?> // if an image was uploaded by user If you want to address all attributes image1, image2, image3, ... and so on and so forth for $img, it should be the solution. Otherwise you would have to clarify what exactly you want to get variables in if statement - El Forum - 06-12-2012 [eluser]brian88[/eluser] thanks. but no luck. the error i get is... Use of undefined constant image - assumed 'image' Code: <?php if( $img->{image.$i} != 'nopic.jpg' ): ?> variables in if statement - El Forum - 06-12-2012 [eluser]PhilTem[/eluser] Ah man, as I was just writing another possible solution, I most likely found your problem Try: Code: <?php if( $img->{'image' . $i} != 'nopic.jpg' ): ?> Gonna give you a beer if it's still not the solution |