空声明未得到我预期的答复

空声明未得到我预期的答复

我从另一个页面打来电话,它正在返回JavaScript幻灯片中的照片,但是,如果该项目没有照片,我需要添加一条消息以弹出。我不断收到错误消息,我不太确定我的逻辑错了..如果我加

        if(!empty($photo)){
          print '<div class="nophoto">There are no photos for item </div>';
    }


我会收到消息,但是如果我单击带有照片的项目,则当照片填充幻灯片时,消息会出现一秒钟。

  <?php
   echo '<div class="container">';
   foreach($value as $photo=>$pictures){
    if(isset($_GET['PhotoVal'])){
      if ($_GET['PhotoVal'] == $photo){
              if(empty($photo)){
             print '<div class="nophoto">There are no photos for this item</div>';
            }
           else
        echo '<div class="flexslider"><ul class="slides">';
      foreach($pictures as $picture){
        echo '<li> <img src="photos/'.$picture.'" /></li>' ;
     }
    echo'</ul></div><a class="close"href="javascript:closeWindow();">Back to Map</a>';
    }
   }
  }

    echo '</div>';
 ?>

最佳答案

您目前所拥有的(带有我的评论):
    

   echo '<div class="container">';

   foreach($value as $photo=>$pictures){

    if(isset($_GET['PhotoVal'])){ // Successful get? Yes - Continue

      if ($_GET['PhotoVal'] == $photo){ // Variable Assignments do not require an if statement unless you already have $photo set to some value

        echo '<div class="flexslider"><ul class="slides">';

        else if (!empty($photo)){ // You don't need an "else" here and you are actually saying "if photo ISN'T empty" which is the same as saying "if photo DOES have a value". So I don't think that you would want to print "There are no photos for this item" when there is a photo

        print '<div class="nophoto">There are no photos for this item</div>';

      }
      foreach($pictures as $picture){
        echo '<li> <img src="photos/'.$picture.'" /></li>' ;
     }
    echo'</ul></div><a class="close"href="javascript:closeWindow();">Back to Map</a>';
    }
   }
  }
    echo '</div>';
 ?>


听起来您正在尝试执行以下操作:

<?php
   echo '<div class="container">'; // Write Container

   foreach($value as $photo=>$pictures){

    if(isset($_GET['PhotoVal'])){ // If we successfully Get PhotoVal proceed

      print 'PhotoVal is set, If you can read this text and there are no images to display then we need to write another if statement within the scope of if(isset($_GET['PhotoVal'])) so we can load placeholder text. If this text doesn't display at all then an else conditional will need to be placed AFTER the if(isset($_GET['PhotoVal'])) statement.';

      $_GET['PhotoVal'] == $photo; // Variable Assignment

      if (empty($photo)) { // If photo is empty write no photo string
          print '<div class="nophoto">There are no photos for this item</div>';
      } else echo '<div class="flexslider"><ul class="slides">';

      foreach($pictures as $picture){

        echo '<li> <img src="photos/'.$picture.'" /></li>' ;
     }

    echo'</ul></div><a class="close"href="javascript:closeWindow();">Back to Map</a>';

    } else {
          print 'PhotoVal was not set =(';
    }

   }
    echo '</div>'; // Close Container ?>

关于php - !空声明未得到我预期的答复,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/16346648/

10-10 23:12