Home  >  Article  >  Backend Development  >  How to delete page records in php and refresh the page at the same time_PHP tutorial

How to delete page records in php and refresh the page at the same time_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 16:59:38872browse

This article introduces a simple method of deleting database records and then refreshing the current page. This is not implemented using ajax but uses the get method to refresh the current page. This method has a poor user experience in practical applications.

Function:

1. Display the query data on a certain page, and add a delete function after each piece of data. Click "Delete" to delete the data and refresh the page at the same time

2. Use GET method to obtain deletion conditions

Database connection variables connectvars.php

 代码如下 复制代码
//服务器
define('DB_HOST', 'localhost');
//用户名
define('DB_USER', 'root');
//密码
define('DB_PASSWORD', 'root');
//数据库
define('DB_NAME','test') ;
?>

The record display page display.php has a "delete" function after each record. Click "Delete" to delete the record and refresh the page at the same time

 代码如下 复制代码

require_once 'connectvars.php';
$dbc = mysqli_connect(DB_HOST,DB_USER,DB_PASSWORD,DB_NAME);
//如果调用此页面时,页面链接中有‘DelID’变量,则获得要删除记录的‘ID’号,进行删除
if(isset($_GET['DelID'])){
$query = "DELETE FROM toyota WHERE ID = ".$_GET['DelID']." LIMIT 1";
mysqli_query($dbc,$query);
}
//查出所有记录,并在接下来的表格中进行显示(如果上面的删除代码被执行,此处相当于刷新页面)
$query = "SELECT * FROM toyota ORDER BY ID DESC";
$data = mysqli_query($dbc,$query);
//统计所查询出的记录条数
$count = mysqli_num_rows($data);
?>

   
        丰田汽车数据查看
   
   
       


       
           
               
               
               
               
               
           
                        //循环输出列表元素:title、source、carType、majorPart,后加一个"删除"链接
              while($row = mysqli_fetch_array($data)){
                  echo '';
                  echo '';
                  echo '';
                  echo '';
                  echo '';
                  //点击"删除"链接,调用自身页面,同时在页面链接上增加‘DelID’变量,赋值为该记录在数据库中的‘ID’号,用于GET方式获得
                  echo '';
                 echo '';
              }
            ?>
       
标题来源车型主要部件操作
'.$row['title'].''.$row['source'].''.$row['carType'].''.$row['majorPart'].'删除

   

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/631292.htmlTechArticleThis article introduces a simple method of deleting database records and then refreshing the current page. This is not implemented using ajax. The get method is used to refresh the current page. This method is actually used in practice...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn