2015-05-29 35 views
-1

海蘭, 我有引導下表有從PHP數據選擇:獲取表元素的ID,並打開附帶數據的模式具有相同的ID

<div class="table-responsive"> 

     <table class="table table-bordered table-hover"> 

      <tr> 
       <th>Nome</th> 
       <th>Cognome</th> 
       <th>Telefono</th> 
       <th>E-mail</th> 
       <th>Azioni Utente</th> 
      <tr> 

      <?php 

       while($contatto = mysql_fetch_assoc($risultati)) { 

        echo "<tr>"; 

        echo "<td>" .$contatto['nome']. "</td>"; 
        echo "<td>" .$contatto['cognome']. "</td>"; 
        echo "<td>" .$contatto['telefono']. "</td>"; 
        echo "<td>" .$contatto['email']. "</td>"; 
        echo "<td> 
        <a href='#' class='btn btn-primary' data-id='".$id = $contatto['id']."'><span class='glyphicon glyphicon-pencil'></span></a></button> 
        </td>"; 
       } 

      ?> 

     </table> 
</div> 

,點擊按鈕,打開我這個模式:

<div id="myModal" class="modal fade" style="padding-top:15%; overflow-y:visible;"> 
    <div class="modal-dialog"> 

     <div class="modal-content"> 

      <div class="modal-header"> 
       <button type="button" class="close" data-dismiss="modal" aria-hidden="true"><span class="glyphicon glyphicon-remove" aria-hidden="true"></span></button> 
       <h4 class="modal-title custom_align" id="Heading">Modifica Dati Contatto</h4> 
      </div> 

       <div class="modal-body"> 
        <div class="form-group"> 
         <input class="form-control" type="text" placeholder="Nome" value = "<?php echo $row[0]; ?>"> 
        </div> 
        <div class="form-group"> 
         <input class="form-control" type="text" placeholder="Cognome"> 
        </div> 
        <div class="form-group"> 
         <input class="form-control" type="text" placeholder="Riferimento (Eventuale)"> 
        </div> 
        <div class="form-group"> 
         <input class="form-control" type="text" placeholder="Numero Telefono"> 
        </div> 
        <div class="form-group"> 
         <input class="form-control" type="text" placeholder="Indirizzo E-mail"> 
        </div> 
       </div> 

       <div class="modal-footer "> 
        <button type="button" class="btn btn-primary btn-lg" style="width: 100%;"><span class="glyphicon glyphicon-ok-sign"></span> Modifica Contatto</button> 
       </div> 

      </div> 
      <!-- /.modal-content --> 
     </div> 
     <!-- /.modal-dialog --> 
    </div> 

與此javascript:

<script type="text/javascript"> 
    $(document).ready(function(){ 
     $('.btn').click(function(){ 
      //get id 
      var id = $(this).data('id'); 
      $("#myModal").modal('show'); 
     }); 
    }); 
</script> 

我想知道什麼是最好的SOLUT離子打開與相同的ID的SQL行的值模態。 在此先感謝您的任何建議

+0

你可能會考慮鏈接模式和按鈕與類。每個頁面的ID應該是唯一的。 –

+0

你有一個例子或網頁? –

+0

最好的辦法是將'json'作爲NightOwlPrgmr,如下所述。 – Alex

回答

0

當按鈕被按下時,我會使用AJAX調用。例如:

<script type="text/javascript"> 
$(document).ready(function() { 
    $('.btn').click(function() { 
     //get id 
     var id = $(this).data('id'); 
     $.ajax({ 
      url: "lookup.php", 
      data: id, 
      type: "POST", 
      cache: false, 
      dataType: "json" 
     }).done(function(response) { 
      // do error checking, etc. 
      if (response) { 
       $("#myModal").modal('show'); 
      } 
     }); 
    }); 
</script> 

然後,如果從數據庫中返回任何數據,則可以使用jQuery將它們附加到模式中。

+0

這是好還是它需要形式?

+0

@DanceF當然,他們說他們需要是SQL的唯一ID以知道要查詢哪些數據;然而,我假設你從數據庫中提取唯一的ID(正確?),因此不應該是一個問題。 – NightOwlPrgmr

+0

正確,所以lookup.php需要包含select(在isset($ _ POST ['action']))之後給出所有值嗎?正確? –