2016-07-09 2 views
-1

안녕하세요, 내 news_id을 트위터 모달로 전달하고 싶습니다. 하지만 잘못된 데이터를 받고 누군가가 내게 모달로 데이터를 전달하는 방법에 대한 아이디어를 줄 수 있습니까?트위터 모달에 데이터 전달

내가 news_id와 뉴스를 삭제 "29"enter image description here

및 삭제 된 데이터가 news_id와 뉴스 "28"입니다 enter image description here

여기 내 코드입니다.

<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와 모달 열리지 만 너무 news_id (28)

제안에 대한 모달되고, ID #myModal와 최초의 모달을 엽니 다 news_id (29)에 대한 두 번째 단추를 않습니다 해결책 : 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

맙소사! 당신의 영웅 @ 크리스 senpai : D 조 감사 마스터. – nethken

+0

다행 이네요. –

+0

님? 채팅으로 이동할 수 있습니까? – nethken

관련 문제