Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 删除时从MySQL数据库实时选择/显示/重新加载数据_Php_Jquery_Mysql - Fatal编程技术网

Php 删除时从MySQL数据库实时选择/显示/重新加载数据

Php 删除时从MySQL数据库实时选择/显示/重新加载数据,php,jquery,mysql,Php,Jquery,Mysql,我有三页: 1index.php从select.php获取结果并将其放入divresult中 php循环到MySQL的表中 php获取user_id作为参数,并将其从MySQL表中删除 我的目标是:用户点击后删除!更改/删除后显示更新结果的步骤 从MySQL的表中 我的问题是我不知道如何告诉jQuery:listenprocessdelete.php?id=123&然后 在保留index.php的同时重新加载select.php,而不重定向到delete.php <?php $co

我有三页:

1index.php从select.php获取结果并将其放入divresult中

php循环到MySQL的表中

php获取user_id作为参数,并将其从MySQL表中删除

我的目标是:用户点击后删除!更改/删除后显示更新结果的步骤

从MySQL的表中

我的问题是我不知道如何告诉jQuery:listenprocessdelete.php?id=123&然后

在保留index.php的同时重新加载select.php,而不重定向到delete.php

<?php
    $con = mysql_connect("localhost","root","123");
    if (!$con) { die('Could not connect: '); }
    mysql_select_db("test", $con);

    $id = mysql_escape_string($_GET["id"]);
    $delete = "delete from users where user_id='{$id}'";
    @mysql_query($delete);
?>
所以用户实际上看不到发生了什么,或者看不到他被重定向到的位置

另一页

index.php

<html>
    <title>a</title>
    <head>
        <script type="text/javascript" src="jquery-1.8.0.js"></script>
        <script type="text/javascript">
            $(function() {
                $('#result').load('select.php');
            });
        </script>
    </head>
    <body>
        <div id="result"></div>
    </body>
</html>
select.php

<?php
    $con = mysql_connect("localhost","root","123");
    if (!$con) { die('Could not connect: '); }
    mysql_select_db("test", $con);

    $result = mysql_query("select * from users");   

    while($rs3 = mysql_fetch_array($result)) {
        echo $rs3["user_email"]." ".$rs3["user_name"]." ";
        echo "<a href=delete.php?id=".$rs3[user_id].">Delete</a>";
        echo "<br />";
    }
?>
delete.php

<?php
    $con = mysql_connect("localhost","root","123");
    if (!$con) { die('Could not connect: '); }
    mysql_select_db("test", $con);

    $id = mysql_escape_string($_GET["id"]);
    $delete = "delete from users where user_id='{$id}'";
    @mysql_query($delete);
?>

谢谢。

不要创建链接,而是创建用于删除的AJAX查询。对链接进行JQuery调用。例如:

<script type="text/javascript">
$(function() {

    function refreshContent(){
        $('#result').load('select.php');    
    }

    $('#result').on('click','a',function(event){
        // prevent going by link `href`
        event.preventDefault();

        // get deleting row id
        var ids = $(this).data('ids');

        // make AJAX call for delete
        $.get("delete.php", { id: ids},function(data){
            // on success - refresh tcontent
            refreshContent();
        });

        return false;
    });

    // making content load on start
    $(document).ready(function(){
        refreshContent();
    });

});
</script>

你在正确的轨道上。您需要做的是:单击“删除”按钮时,使用ajax jquery可以轻松地调用delete.php并从单击“删除”按钮的表中删除行。这样就不需要重新加载表。当然,只有在收到来自“delete.php”@eawedat的成功响应并检查我的答案编辑后,您才需要删除该行。我尝试了另一种方法,但不知道将其发布到何处。因为在注释中没有颜色,而且我的代码很长。select.php:index.php:这是一种非常糟糕的方式。因为任何没有JS支持的人都无法浏览你的网站。但是。。您可以使用js加载内容,所以不必介意:但我强烈建议在上使用jquery方法。