AJAX/PHP - 如何将发布的数据加载到同一页面上的模式中 [英] AJAX / PHP - How to get posted data to load into a modal on the same page

查看:23
本文介绍了AJAX/PHP - 如何将发布的数据加载到同一页面上的模式中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试制作一个支持票系统.https://gyazo.com/f87fde8cfacf2165a373f409954cf653.

当一个复选框被选中时,它会选择用户 ID(工作).但是我想这样做,当他们选择用户时单击绿色回复按钮时,获取与他们的用户 ID 相对应的信息,以便我可以显示他们打开的所有支持票.所以我可以通过模态添加另一个回复.像这样:https://gyazo.com/6fb77589606b1e24160c52885b987624但是对于这个例子,我使用的是静态用户名 fetch .例如 ... FROM support WHERE post_by = 'Chowderrunnah'.Chowderrunnah 是用户的名字.

我希望它通过选定的复选框(工作)获取用户 ID,并让它获取他们打开的所有支持票.

这是我的 phpmyadmin 数据库:https://gyazo.com/f9eb86e2877979182f6a2a535c6

下面是我(尝试)做但不工作的代码.php 标签中的页面顶部

函数grab_selected_users_support() {全球 $con;全局 $user_reply_id;$用户名 = $_SESSION['用户名'];$users_support_sql = "SELECT id, message,posted_by, last_post_by, date_posted, status FROM support WHEREposted_by = 'Chowderrunnah' ORDER BY id DESC";$result = $con->query($users_support_sql) or die("Error");而 ($row = mysqli_fetch_assoc($result)) {$usersSupport_id = $row['id'];$usersSupport_message = $row['message'];$usersSupport_posted_by = $row['posted_by'];$usersSupport_last_post_by = $row['last_post_by'];$usersSupport_date_posted = $row['date_posted'];$usersSupport_status = $row['status'];?><div class="well well-sm col-lg-12 pull-left"><span><strong><?php echo $usersSupport_last_post_by ?></strong>: <?php echo $usersSupport_message;?><br><br><?php echo $usersSupport_status == 'Open' ?'<span class="label label-success">打开</span>': '<span class="label label-danger">Closed</span>'?></b><hr><i><?php echo $usersSupport_date_posted;?></i></span>

<?php ;}}

我的 PHP 检查

您必须至少选择一张支持票才能删除 <i class="fa fa-spin fa-spinner"></i></div>';}}if(isset($_POST['add_reply_submit'])) {if(!empty($_POST['checked_id'])) {$idArrr = $_POST['checked_id'];$用户名 = $_SESSION['用户名'];foreach($idArrr 作为 $idd) {$user_reply_id = mysqli_query($con, "SELECT Posted_by FROM support WHERE id = '$idd'");}}别的 {echo '<div class="row" style="color: red; text-align: center; padding-bottom: 20px;"><i class="fa fa-spin fa-spinner"></i>您必须至少选择一张支持票才能回复 <i class="fa fa-spin fa-spinner"></i></div>';}}?>

HTML 按钮

<button type="button" data-toggle="modal" data-target="#myModal" class="btn btn-primary"><i class="fa fa-info"></i><button type="submit" class="btn btn-danger" name="bulk_delete_submit"><i class="fa fa-trash-o"></i></button><button name="add_reply_submit" class="btn btn-success wave-effect wave-light" type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myReplyModal"><i class="fa fa-reply"></i>

<div class="table-responsive"><table class="table m-0" id="table"><头><tr style="font-size: 11px;"><th><input type="checkbox" id="selectall"/></th><th class="table-header">Message</th><th class="table-header">发布者</th><th class="table-header">Last Post By</th><th class="table-header">发布日期</th><th class="table-header">状态</th></tr></thead><?phpforeach($faq as $k=>$v) {?><tr class="table-row" style="text-align: left;"id="no_enter"><td style="font-size: 11px;"><input type="checkbox" name="checked_id[]" class="checkbox" value="<?php echo $faq[$k]["id"]; ?>"></td><td style="字体大小:11px;"contenteditable="true" onBlur="saveToDatabase(this,'message','<?php echo $faq[$k]["id"]; ?>')" onClick="showEdit(this);"><?php echo $faq[$k]["message"] != '' ?$faq[$k]["message"] : '无';?></td><td style="字体大小:11px;"contenteditable="true" onBlur="saveToDatabase(this,'posted_by','<?php echo $faq[$k]["id"]; ?>')" onClick="showEdit(this);"><?php echo $faq[$k]["posted_by"] != '' ?$faq[$k]["posted_by"] : '无';?></td><td style="字体大小:11px;"contenteditable="true" onBlur="saveToDatabase(this,'last_post_by','<?php echo $faq[$k]["id"]; ?>')" onClick="showEdit(this);"><?php echo $faq[$k]["last_post_by"] != '' ?$faq[$k]["last_post_by"] : '无';?></td><td style="字体大小:11px;"contenteditable="true" onBlur="saveToDatabase(this,'date_posted','<?php echo $faq[$k]["id"]; ?>')" onClick="showEdit(this);"><?php echo $faq[$k]["date_posted"] != '' ?$faq[$k]["date_posted"] : '无';?></td><td style="字体大小:11px;"contenteditable="true" onBlur="saveToDatabase(this,'status','<?php echo $faq[$k]["id"]; ?>')" onClick="showEdit(this);"><?php echo $faq[$k]["status"] != '' ?($faq[$k]["status"] == 'Open' ? '<span class="label label-success">Open</span>' : '<span class="label label-danger">Closed</span>') : '无';?></td><?php}?></tbody>

</表单>

我的模态

 <div id="myReplyModal" class="modalfade" role="dialog"><div class="modal-dialog"><!-- 模态内容--><div class="modal-content"><div class="modal-header"><button type="button" class="close" data-dismiss="modal">&times;</button><h4 class="modal-title">模态标题</h4>

<div class="modal-body"><form class="form-horizo​​ntal" role="form" method="post"><?phpgrab_selected_users_support();?><div class="row"><div class="col-sm-12"><div class="text-center p-20"><button class="btn w-sm btn btn-primary wave-effect" type="submit" name="addReply">保存更改</button><button type="button" class="btn w-sm btn-danger wave-effect" data-dismiss="modal" aria-hidden="true">关闭</button>

</表单>

<div class="modal-footer"><button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>

解决方案

您正在表单中使用