开发者

Help with a php if statement

can somebody help me with this if statement? My form appears every-time I load the page but it disappears after I submit the form! Maybe it's the "endif" syntax that confuses me but I can't get this done properly... here is the code:

<?php
if ($this->input->post('submit') && $this->input->post('categories')):
  foreach($tagedImages as $image):
  ?>
    <div class="thumb">
      <?php  echo'<a href="/toKoritsi/uploads/'.$image.'"/> <img src="/toKoritsi/uploads/thumbs/'.$image.'"/></a>' ?>
    </div>
  <?php
  endforeach;
elseif(isset($photosQuery) && count($photosQuery)):
  foreach($photosQuery->result_array() as $photo):
  ?>
    <div class="thumb">
      <?php echo'<a href="/toKoritsi/uploads/'.$photo['name'].'"/> <img src="/toKoritsi/uploads/thumbs/'.$photo['name'].'"/></a>' ?>
    </div>
  <?php
   endforeach;
endif;

$options = array(
  'bracelet'  => 'Bracelets',
  'ring'      => 'Rings',
  'bag'       => 'Bags',
  'earing'    => 'Earings'
);

echo form_open("toKoritsi/gallery");
echo form_dro开发者_如何转开发pdown('categories', $options, 'bracelet');
echo form_submit('submit', 'Choose');
echo form_close();
?>

thanks in advance!


Should foreach($tagedImages as $image) be foreach($taggedImages as $image)?

The formatting of your code is very ugly. If you are intent on getting nicely-formatted HTML output, perhaps you should consider using Tidy, or a template engine that offers that functionality.


I don´t know what the url structure of your site looks like, but are you sure you are submitting the form to the right place?

According to the CI user guide, it gets submitted to something like /index.php/toKoritsi/gallery but that depends on your config preferences.


You definitely need to format your code properly.

I'd also recommend trying to consolidate your PHP into blocks, and keep it separate from your HTML.

You can do all the conditionals and echos WITHIN some of those HTML elements:

<div>
<?php /*...*/ ?>
</div>

as opposed to what you're doing now:

<?php /*...*/ ?>
<div>
<?php /*...*/ ?>
</div>
<?php /*...*/ ?>

In addition, things like these blocks make no sense:

    <?php endforeach;?>
            <?php endif;?>

Even if you had to break your code into small chunks, wouldn't it be easier to say:

<?php
    endforeach;
    endif;
?>

EDIT: This answer was provided before the question source was reformatted and cleaned up. I was unable to even address the original issue until I could better see what was going on.

This might sound kind of dumb, but are you sure that your gallery controller is behaving correctly? If you're submitting and there's an error in one of your CodeIgniter functions, it could be messing up the rendering after the submit.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜