1

我从另一个页面打来电话,它在 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>';
 ?>
4

1 回答 1

0

您目前拥有的(以及我的评论):

   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 ?>
于 2013-05-02T20:13:23.787 回答