将数据传递给twitter模式

时间:2016-07-09 06:05:51

标签: php jquery twitter-bootstrap twitter

您好我想将news_id传递给twitter模式。但是我得到了错误的数据有人可以给我一些关于如何将数据传递给模态的想法吗?

我用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 个答案:

答案 0 :(得分:1)

错误在于您声明模态的方式。

news_id 28的第一个删除按钮打开标识为#myModal的模式,但news_id 29的第二个按钮也是如此,它打开第一个标识为#myModal的模式,作为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">

应该修复它。