【问题标题】:Pass data to the twitter modal将数据传递到 twitter 模式
【发布时间】:2016-11-11 17:55:05
【问题描述】:

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

我删除 news_id 为“29”的新闻

删除的数据是 news_id 为“28”的新闻

这是我的代码。

  <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');
}
?>

【问题讨论】:

    标签: php jquery twitter-bootstrap twitter


    【解决方案1】:

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

    news_id 28 的第一个删除按钮会打开 id 为 #myModal 的模态,但 news_id 29 的第二个按钮也会打开第一个 id 为 #myModal 的模态,即 news_id 28 的模态。

    建议的解决方案:将 ID 添加到模态框。

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

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

    应该修复它。

    【讨论】:

    • 天哪!你我的英雄@Chris senpai :D 谢谢主人。
    • 先生?我们可以开始聊天吗?
    • 抱歉,我没有时间提供个人支持。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-02-19
    • 2019-03-31
    • 2019-12-30
    • 1970-01-01
    • 1970-01-01
    • 2019-11-18
    • 2022-01-17
    相关资源
    最近更新 更多