2015-06-21 62 views
0

我有這個tabel數據rfid mac標籤。這些標籤我想在彈出窗口中顯示,並在按下時顯示一些額外的信息。但它並不像桌子本身那樣改變它的價值。流行似乎重複了它給出的第一個價值。如何在每個while循環後更改彈出窗口的值?Bootstrap Popover不會改變while循環中的值

<div class="panel panel-default panel-success"> 
    <div class="panel-heading"> 
    <h3 class="panel-title">Items inside</h3> 
    </div> 

    <table class="table table-bordered text-center"> 
    <?php 
     $result = mysqli_query($con, "SELECT item_tag, item_status FROM item WHERE item_status = 1;") or die(mysql_error()); 

     $i = 0; 
     while ($row = mysqli_fetch_array($result)){ 
     $i++; 
     //if this is first value in row, create new row 
     if ($i % 3 == 1) { 
      echo "<tr>"; 
     } 
     ?> 

     <td> 
     <div> 
      <span class="btn" id="infoItem" data-toggle="popover" rel="popover"> 
      <?php echo $row[0] ?> 
      </span> 
     </div> 
     </td> 

     <script> 
     $(document).ready(function() { 
      $('[data-toggle="popover"]').popover({ 
      html: true, 
      animation: false, 
      content: '<?php echo $row[0] ?>', 
      placement: "bottom" 
      }); 
     }); 
     </script> 
     <?php 
     //if this is third value in row, end row 
     if ($i % 3 == 0) { 
      echo "</tr>"; 
     } 
     } 
     //if the counter is not divisible by 3, we have an open row 
     $spacercells = 3 - ($i % 3); 
     if ($spacercells < 3) { 
     for ($j = 1; $j <= $spacercells; $j++) { 
      echo "<td></td>"; 
     } 
     echo "</tr>"; 
     } 
    ?> 
    </table> 

</div> 

這是我第一次使用HTML/PHP/MySQL的/引導應用。

回答

0

如果我是你,我會利用引導數據屬性API。類似於

<div class="panel panel-default panel-success"> 
    <div class="panel-heading"> 
    <h3 class="panel-title">Items inside</h3> 
    </div> 

    <table class="table table-bordered text-center"> 

    <?php 
    $result = mysqli_query($con, "SELECT item_tag, item_status FROM item WHERE item_status = 1;") or die(mysql_error()); 

    $i = 0; 
    while ($row = mysqli_fetch_array($result)){ 
    $i++; 
    //if this is first value in row, create new row 
    if ($i % 3 == 1) { 
     echo "<tr>"; 
    } 
    ?> 

     <td> 
     <div> 
      <span data-placement="bottom" data-content="<?php echo $row[0]; ?>" data-animation="false" data-html="true" class="btn" id="infoItem" data-toggle="popover" rel="popover"> 
      <?php echo $row[0]; ?> 
      </span> 
     </div> 
     </td> 

    <?php 
    //if this is third value in row, end row 
    if ($i % 3 == 0) { 
     echo "</tr>"; 
    } 
    } 

    </table> 

</div> 


<script type="text/javascript"> 

     $(document).ready(function() { 
      //Init all the popovers with one call 
      $('[data-toggle="popover"]').popover('show'); 

     }); 

</script>