2016-07-09 3 views
-1

こんにちは、news_idをtwitter modalに渡したいと思います。しかし、間違ったデータを取得している人誰かに私にモーダルにデータを渡す方法のアイデアを教えてもらえますか?twitter modalにデータを渡す

ここでは "28" enter image description here

を私はnews_idで "29" enter image description here

をニュースを削除し、削除されたデータは、news_idとニュースで私のコードです。

<div class="container"> 
     <table class="table table-bordered" > 
      <thead> 
       <tr> 
        <th width="60">ID</th> 
        <th width="200">News Title</th> 
        <th width="150">Date Posted</th> 
        <th>Content</th> 
        <th width="200">Image</th> 
        <th width="200">Action</th> 
       </tr> 
      </thead> 
      <tbody> 
      <?php 

      $stmt = mysqli_prepare($con, "SELECT * FROM news ORDER BY news_id"); 
      mysqli_stmt_execute($stmt); 
      $result = mysqli_stmt_get_result($stmt); 
      while($row = mysqli_fetch_array($result)){ 
      ?> 
       <tr> 
        <td><?php echo $row['news_id']; ?></td> 
        <td><?php echo $row['news_title']; ?></td> 
        <td><?php echo $row['news_date']; ?></td> 
        <td><?php echo $row['news_content']; ?></td> 
        <td><img style="height:150px; width:200px;" src="<?php echo $row['news_image']; ?>" ></td> 
        <td> 
         <a class='btn btn-info left-margin' href="edit2.php?newsid=<?php echo $row['news_id'];?>" ><span class="glyphicon glyphicon-edit"></span> Edit</a> 
         <a class='btn btn-danger delete-object' data-toggle="modal" data-target="#myModal"><span class="glyphicon glyphicon-remove"></span> Delete</a> 

           <div class="modal fade" id="myModal" role="dialog" aria-labelledby="myModalLabel"> 
            <div class="modal-dialog" role="document"> 
             <div class="modal-content"> 
              <div class="modal-body"> 
               Are you sure you want to delete this? 
              </div> 
             <div class="modal-footer"> 
              <a class='btn btn-danger left-margin' href="delete.php?newsid=<?php echo $row['news_id'];?>" >Yes</a> 
              <button type="button" class="btn btn-default" data-dismiss="modal">No</button> 
             </div> 
             </div> 
            </div> 
           </div> 

        </td> 
       </tr> 
      <?php 
      } 
      ?> 
      </tbody> 
     </table> 
    </div> 

は、ここに私のdelete.php

<?php 
include_once('connection.php'); 
$newsid = $_GET['newsid']; 

if(isset($newsid)){ 
     $stmt = mysqli_prepare($con, "DELETE FROM news WHERE news_id = ?"); 
     mysqli_stmt_bind_param($stmt, "s", $newsid); 
     mysqli_stmt_execute($stmt); 
     header('location: edit.php'); 
} 
?> 

答えて

1

エラーは、あなたのモーダルを宣言する方法に存在しています。

news_id 28のためのあなたの最初の削除ボタンは、ID #myModalとモーダルを開きますが、そのID #myModalとの最初のモーダルを開くnews_id 29のための第二のボタンは、ありません、提案news_id 28

のためのモーダルであること解決策:IDをモーダルに追加します。

<a class='btn btn-danger delete-object' data-toggle="modal" data-target="#modal<?php echo $row['news_id'];?>"><span class="glyphicon glyphicon-remove"></span> Delete</a>

<div class="modal fade" id="modal<?php echo $row['news_id'];?>" role="dialog" aria-labelledby="myModalLabel">

それを修正する必要があります。

+0

私の神!あなたの私のヒーロー@クリス先輩:Dありがとうマスター。 – nethken

+0

うれしいよ:) –

+0

サー?私たちはチャットに移動できますか? – nethken

関連する問題