2014-10-07 226 views
-1

我的目標是打開具有模式ID的循環$ viewhh中鏈接的詳細信息。我已經通過jQuery等嘗試了很多不同的方法,並且無法獲得任何工作。只是調用頁面正常工作,但嘗試加載模式對我來說是徒勞的。將變量傳遞給jquery

<div class="row"> 
      <div class="col-md-12"> 
       <p><a class="btn btn-default" href="add_praise.php" role="button">Add a Praise</a></p> 
       <h2>Praises</h2> 
       <p><?php 
        $query = "SELECT praise.id, praise.title, praise.description, praise.created, member.username FROM praise INNER JOIN member ON praise.member_id=member.id ORDER BY praise.created desc;"; 
        $stmt = $db->query($query); 
        printf('<table class="table">'); 
        printf('<thead><tr><th>Title</th><th>Posted By</th><th>Posted</th></tr></thead>'); 
        while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { 
         $created = date('m-d-Y', strtotime($row['created'])); 
         $viewhh = '<a href="view_praise.php?id=' . 
           urlencode($row["id"]) . '">' . ($row["title"]) . '</a>'; 
         printf("<tbody><tr><td> %s </td> <td> %s </td><td> %s </td><td> %s </td></tr></tbody>", $viewhh, htmlentities($row["username"]), $created, $viewbutton); 
         printf("</table"); 
        } 
        ?> </p> 

      </div> 

這是被稱爲

<?php 
$praiseid = urldecode($_GET['id']); 
$sth = $db->prepare("select * from praise where id = '$praiseid'"); 
$sth->execute(); 
      $result = $sth->fetch(PDO::FETCH_ASSOC); 
      $title = $result['title']; 
        $description= $result['description']; 


      ?> 
<div class="container"> 
    <!-- Example row of columns --> 
    <div class="row"> 
     <div class="col-md-4"> 

      <h2><?php echo $title; ?></h2> 
      <div><?php echo $description; ?></div> 

     </div> 
</div> 

頁我曾嘗試加入這個,但現在只得到了第一個記錄。

<script> 
     $(function() { 

      $("#loadpraise").colorbox({ iframe: true, width: "90%", height: "90%", closeButton: false }); 

      $("#events").colorbox({ 
       onOpen: function() { alert("Colorbox onOpen"); }, 
       onLoad: function() { alert("Colorbox onLoad"); }, 
       onComplete: function() { alert("Colorbox onComplete"); }, 
       onCleanup: function() { alert("Colorbox onCleanup"); }, 
       onClosed: function() { alert("Colorbox onClosed"); } 
      }); 

      $("#childForm").colorbox({ closeButton: false, onClosed: function() { alert($.colorbox.popupResult) } }); 
     }); 
    </script> 
+1

有什麼具體問題? – 2014-10-07 19:50:16

+1

哪裏是js代碼? – shampoo 2014-10-07 19:56:10

+1

這看起來[恐怖不安全](http://bobby-tables.com/)。你確定**你的用戶參數是[妥善轉義](http://bobby-tables.com/php)?使用PDO時,請務必使用[預準備語句](http://php.net/manual/en/pdo.prepared-statements.php)以避免手動轉義或處理引用問題。 – tadman 2014-10-07 20:23:08

回答

0

我得到它使用BootStrap 3模態工作。

鏈接調用記錄:剛纔添加的數據切換=「模式」和數據目標=「#myModal」

$viewpraise = '<a data-toggle="modal" href="view_praise.php?id=' . urlencode($row["id"]) . '" data-target="#myModal">' . ($row["title"]) . '</a>'; 

包括在同一頁上的遠程調用的模式。遠程頁面被加載到「模態內容」div中。

​​

然後叫加模態其餘內容頁面上:

<!DOCTYPE html> 
<html> 
<head> 
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"> 
    <title>Remote file for Bootstrap Modal</title> 
    <script> 

    $('body').on('hidden.bs.modal', '.modal', function() { 
     $(this).removeData('bs.modal'); 
     });</script> 

</head> 
<body> 
      <div class="modal-header"> 
       <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button> 
       <h4 class="modal-title">Modal title</h4> 
      </div>   <!-- /modal-header --> 
      <div class="modal-body"> 
      <h2><?php echo $title; ?></h2> 
      <div><?php echo $description; ?></div> 
      </div>   <!-- /modal-body --> 
      <div class="modal-footer"> 
       <button type="button" class="btn btn-default" data-dismiss="modal">Close</button> 
<!--    <button type="button" class="btn btn-primary">Save changes</button>--> 
      </div>   <!-- /modal-footer --> 
</body> 
</html>