微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

PHP jQuery Tabledit 选择选项

如何解决PHP jQuery Tabledit 选择选项

我正在尝试使用 jQuery tabledit 插件制作动态表。所以我有一张包含用户的表和一张包含用户类型(管理员、员工、客户)的表。这两个表之间的关系是通过 user_type_id。我需要的是选择表 user_type 中的选项,因此当管理员想要编辑有关某些用户的信息时,他可以在选择中查看 user_type 表中的值,并且当他从中选择选项时选择,数据库中的数据将被更新。

这就是html表格的样子

enter image description here

这是两个表的关系

enter image description here

employess.PHP

<?PHP 
$con = MysqLi_connect("localhost","root","","gym_project_db");
$query = "SELECT * FROM user WHERE user_type_id = 1";
$result = MysqLi_query($con,$query);

$query2 = "SELECT * FROM user_type";
$result2 = MysqLi_query($con,$query2);
?>
<!DOCTYPE html>
<html>
<head>
    <title></title>
    <link rel="stylesheet" type="text/css" href="css/main_page.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />  
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>      
    <script src="js/jquery.tabledit.js"></script>     
    <script src="js/jquery.multi-select.js"></script>  
</head>
<body>
    <div class="wrapper">
        <div class="sidebar">
            <h2>Gym management system</h2>
            <ul>
                <li><a href="#"><i class="fas fa-home"></i>Dashboard</a></li>
                <li><a href="employess.PHP"><i class="fas fa-user"></i>Employees</a></li>
                <li><a href="#"><i class="fas fa-address-card"></i>Clients</a></li>
                <li><a href="#"><i class="fas fa-project-diagram"></i>Subscriptions</a></li>
                <li><a href="#"><i class="fas fa-blog"></i>Branches</a></li>
                <li><a href="#"><i class="fas fa-address-book"></i>Cards</a></li>
                <li><a href="#"><i class="fas fa-address-book"></i>Profile</a></li>
                <li><a href="#"><i class="fas fa-map-pin"></i>logout</a></li>
            </ul> 
        </div>
        <div class="main_content">
            <div class="header">Welcome!! Have a nice day.</div>  
            <div class="info">

                <div class="employess">

                    <table id="editable_table" class="table table-bordered table-striped">
                        <thead>
                            <tr>
                                <th>User_id</th>
                                <th>Username</th>
                                <th>Password</th>
                                <th>Name</th>
                                <th>Surname</th>
                                <th>EGN</th>
                                <th>Email</th>
                                <th>Phone</th>
                                <th>Address</th>
                                <th>User_type_id</th>
                            </tr>
                        </thead>
                        <tbody>

                            
                            <?PHP while($row = MysqLi_fetch_array($result)){ ?>
                                <tr>
                                    <td> <?= $row["user_id"] ?></td>
                                    <td> <?= $row["username"] ?></td>
                                    <td> <?= $row["password"] ?></td>
                                    <td> <?= $row["name"] ?></td>
                                    <td> <?= $row["surname"] ?></td>
                                    <td> <?= $row["egn"] ?></td>
                                    <td> <?= $row["email"] ?></td>
                                    <td> <?= $row["phone"] ?></td>
                                    <td> <?= $row["address"] ?></td>
                                    <?PHP 
                                    $user_type_query = MysqLi_query($con,"SELECT user_type_id,user_type FROM user_type WHERE user_type_id = $row[9]");
                                    $typerow = MysqLi_fetch_array($user_type_query);
                                    ?>
                                    <td><?= $typerow[1]; ?></td>

                                </tr>


                            <?PHP }?>

                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </body>
    </html>

    <script>  
        $(document).ready(function(){ 
            $('#editable_table').tabledit({
                url:'employee_action.PHP',columns:{
                    identifier:[0,"user_id"],editable:[[1,'username'],[2,'password'],[3,'name'],[4,'surname'],[5,'egn'],[6,'email'],[7,'phone'],[8,'address'],[9,'user_type_id']
                    ]
                },restoreButton:false,onSuccess:function(data,textStatus,jqXHR)
                {
                    if(data.action == 'delete')
                    {
                        $('#'+data.id).remove();
                    }
                }
            });

        });
</script>

employee_action.PHP

<?PHP  

$connect = MysqLi_connect("localhost","gym_project_db");

$input = filter_input_array(INPUT_POST);


if($input["action"] === 'edit')
{
 $query = "
 UPDATE user
 SET 

 username = '". $input["username"] ."',password = '". $input["password"] ."',name = '". $input["name"] ."',surname = '". $input["surname"] ."',egn = '". $input["egn"] ."',email = '". $input["email"] ."',phone = '". $input["phone"] ."',address = '". $input["address"] ."'
 
 WHERE user_id = '".$input["user_id"]."'
 ";

 MysqLi_query($connect,$query);

}



if($input["action"] === 'delete')
{
 $query = "
 DELETE FROM user 
 WHERE user_id = '".$input["user_id"]."'
 ";
 MysqLi_query($connect,$query);
}

echo json_encode($input);

?>

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。