duanrenchuo9244 2016-09-12 11:21
浏览 22

如何更新表而不更改显示的屏幕数据

I need to display a simple list of hundreds of items which are on a MySQL table, review the list onscreen and click on a link beside each unwanted item to delete it from the table. This is an internal management procedure; no outside user is involved. I do not need the item to disappear from the list immediately; I will refresh the list periodically so items deleted from the table are no longer listed. I do not need any message to confirm that the item has been deleted. The important thing is that I don't want to lose sight of the list each time I delete an item and have to click on a "go back" button to return to the list.

The table uses MySQL. All my coding to date has been in PHP. So I am using php to display the list of items, on a non-html screen. This is the code for each item:

echo $item." <a href='item_delete.php?id=".$item."'>Delete item</a><br />";

This is the code for item_delete.php:

<?php
require ('connect.php');    //  To define connection $con
$id = $_POST['id'];
mysqli_query($con, "DELETE FROM `items_table` WHERE `id` = $id");
?>

The item is deleted correctly but a blank screen is (understandably) displayed.

I have done a lot of searching but most people needing help want to do more advanced things and - because I have so far managed to avoid learning JavaScript, jQuery and AJAX - I can't even work out which of those technologies I need to update a table without changing the screen.

I get the impression that each PHP script always takes "focus" with it, so maybe I need a little JavaScript script to do this ? If so: - can I just change item_delete.php to item_delete.js or do I have to define the non-html list as an html one ? - what js code is needed in item_delete.js ?

I have read about using: header("location:javascript://history.go(-1)"); or: header('Location: ' . $_SERVER['HTTP_REFERER']); but they don't go back to the onscreen list.

I don't think I want the js script to perform a virtual "go back" because the list is originally produced by using (about 20) $_POST parameters, so I still seem to have to refresh it each time.

So I'd like a solution to remain with the list - rather than leave it and return to it. Thanks.

  • 写回答

3条回答 默认 最新

  • dongyi7901 2016-09-12 11:30
    关注

    It would make a lot of sense to do the deletion asynchronously using javascript. However, the simplest and messiest way to achieve what you want, is to add target="_blank" to the links, (which will leave you with a open blank tab for each delete request you do).

    echo $item." <a href='item_delete.php?id=".$item."'       target='_blank'>Delete item</a><br />";
    

    Or you can solve it by adding checkboxes in front of every item, check the items you want to delete and submit them as form parameters to the delete script.

    评论

报告相同问题?

悬赏问题

  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100