试图从选中的复选框中获取POST,并将用户id对应的用户数据加载到Modal中


Trying to get the POST from a checked checkbox and load the users data corresponding to that users id into a Modal

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

当一个复选框被选中时,它选择用户ID(工作)。但我想做到这一点,当绿色回复按钮被点击时,他们有一个用户选择,抓住他们的信息对应于他们的用户id,这样我就可以显示所有的支持票,他们已经打开。所以我可以通过模态添加另一个回复。像这样:https://gyazo.com/6fb77589606b1e24160c52885b987624。但在本例中,我使用的是静态用户名获取。如……FROM support WHERE postd_by = 'Chowderrunnah'。Chowderrunnah是用户名

我希望它通过选中的复选框(工作)获得用户id,并使其抓住他们打开的所有支持票。

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

下面是我的代码,我(试图)做什么,但不工作

页顶在php标记

function grab_selected_users_support() {
global $con;
global $user_reply_id;
    $username           = $_SESSION['username'];
    $users_support_sql   = "SELECT id, message, posted_by, last_post_by, date_posted, status FROM support WHERE posted_by = 'Chowderrunnah' ORDER BY id DESC";
    $result             = $con->query($users_support_sql) or die("Error");
        while ($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">Open</span>' : '<span class="label label-danger">Closed</span>' ?></b><hr><i><?php echo $usersSupport_date_posted; ?></i></span>
                </div>
                <?php ;
        }
}

My PHP检查

<?php 
if(isset($_POST['bulk_delete_submit'])) {
    if(!empty($_POST['checked_id'])) {
        $idArr = $_POST['checked_id'];
        $username = $_SESSION['username'];
        foreach($idArr as $id) {
            mysqli_query($con, "DELETE FROM support WHERE id = '$id'");
            echo "<p>".$id ."</p>";
        }
        $_SESSION['success_msg'] = 'Support Ticket have been deleted successfully.';
        header("Location: admin_support.php");
    }
    else { 
        echo '<div class="row" style="color: red; text-align: center; padding-bottom: 20px;"><i class="fa fa-spin fa-spinner"></i> You must select atleast one support ticket to delete <i class="fa fa-spin fa-spinner"></i></div>';
    }
}
if(isset($_POST['add_reply_submit'])) {
    if(!empty($_POST['checked_id'])) {
        $idArrr = $_POST['checked_id'];
        $username = $_SESSION['username'];
        foreach($idArrr as $idd) {
            $user_reply_id = mysqli_query($con, "SELECT posted_by FROM support WHERE id = '$idd'");
        }
    }
    else { 
        echo '<div class="row" style="color: red; text-align: center; padding-bottom: 20px;"><i class="fa fa-spin fa-spinner"></i> You must select atleast one support ticket to reply to <i class="fa fa-spin fa-spinner"></i></div>';
    }
}

?>

HTML按钮

    <form name="bulk_action_form" action="" class="form-inline" method="POST"/>
<button type="button" data-toggle="modal" data-target="#myModal" class="btn btn-primary">
    <i class="fa fa-info"></i>
</button>
<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 waves-effect waves-light" type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myReplyModal">
    <i class="fa fa-reply"></i>
</button>
</div>
</div>
<div class="table-responsive">
<table class="table m-0" id="table">
<thead>
<tr style="font-size: 11px;">
<th><input type="checkbox" id="selectall"/></th>
<th class="table-header">Message</th>
<th class="table-header">Posted By</th>
<th class="table-header">Last Post By</th>
<th class="table-header">Date Posted</th>
<th class="table-header">Status</th>
</tr>
</thead>
<tbody>
<?php
foreach($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="font-size: 11px;" contenteditable="true" onBlur="saveToDatabase(this,'message','<?php echo $faq[$k]["id"]; ?>')" onClick="showEdit(this);"><?php echo $faq[$k]["message"] != '' ? $faq[$k]["message"] : 'None'; ?></td>
<td style="font-size: 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"] : 'None'; ?></td>
<td style="font-size: 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"] : 'None'; ?></td>
<td style="font-size: 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"] : 'None'; ?></td>
<td style="font-size: 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>') : 'None'; ?></td>
<?php
}
?>
</tbody>
</table>
</div>
</div>
</form>

我的模态

        <!-- Reply to ticket modal -->
    <div id="myReplyModal" class="modal fade" role="dialog">
      <div class="modal-dialog">
        <!-- Modal content-->
        <div class="modal-content">
          <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal">&times;</button>
            <h4 class="modal-title">Modal Header</h4>
          </div>
          <div class="modal-body">
            <form class="form-horizontal" role="form" method="post">
              <?php grab_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 waves-effect" type="submit" name="addReply">Save Changes</button>
                            <button type="button" class="btn w-sm btn-danger waves-effect" data-dismiss="modal" aria-hidden="true">Close</button>
                        </div>
                    </div>
                </div>
            </form>
          </div>
          <div class="modal-footer">
            <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
          </div>
        </div>
      </div>
    </div>
    下面一行的
  1. type="button"不会提交表单,因此表单输入将不会被提交。

<button name="add_reply_submit" class="btn btn-success waves-effect waves-light" type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myReplyModal"> <i class="fa fa-reply"></i> </button>

  • 更改type="submit"将提交表单输入,但由于页面重新加载,它将不显示modal

    因此最好的方法是使用AJAX提交表单,并在success函数中调用modal()方法。