Welcome Guest, Not a member yet? Register   Sign In
variables in if statement
#1

[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:
&lt;?php for ($i=1; $i<=$num_of_images ; $i++): ?&gt;
  // this $i does not work, unknown var
   &lt;?php if( $img->image.$i != 'nopic.jpg' ): ?&gt;

heres the full code

controller
Code:
$data['images'] = $this->main_mod->getImages();
$data['num_of_images'] = 8;

// views
$data['content'] = 'main/post';
$this->load->view('templates/main', $data);

view
Code:
&lt;?php foreach($images as $img): ?&gt;
   <p>&lt;?php echo $img->name; ?&gt;</p>

  &lt;?php for ($i=1; $i<=$num_of_images ; $i++): ?&gt;
  // this $i does not work, unknown var
   &lt;?php if( $img->image.$i != 'nopic.jpg' ): ?&gt; // if an image was uploaded by user

   <img src="&lt;?php echo base_url('assets/images/').'/'.$img-&gt;image . $i; ?&gt;" width="30" alt=""><br />

   &lt;?php endif; ?&gt;
  &lt;?php endfor; ?&gt;
&lt;?php endforeach; // end ?&gt;


Messages In This Thread
variables in if statement - by El Forum - 06-12-2012, 09:05 AM
variables in if statement - by El Forum - 06-12-2012, 09:20 AM
variables in if statement - by El Forum - 06-12-2012, 10:12 AM
variables in if statement - by El Forum - 06-12-2012, 10:31 AM



Theme © iAndrew 2016 - Forum software by © MyBB