Delete page records in php and refresh the page. This article introduces a simple method to refresh the current page when deleting database records. this is not implemented using ajax, but by using get to refresh the current page, this method is used in practical applications. This article introduces how to refresh the current page when deleting a database record. this method is not implemented by ajax but refreshed by get, this method has poor user experience in practical applications.
Function:
1. query data is displayed on a page, and the delete function is added after each data entry. click "delete" to delete the data and refresh the page.
2. GET deletion conditions
Database connection variable connectvars. php
The code is as follows: |
|
// Server Define ('Db _ host', 'localhost '); // User name Define ('Db _ user', 'root '); // Password Define ('Db _ password', 'root '); // Database Define ('Db _ name', 'test '); ?> |
The record display page is displayed. php. each record has the "delete" function. click "delete" to delete the record and refresh the page.
The code is as follows: |
|
Require_once 'connectvars. php '; $ Dbc = mysqli_connect (DB_HOST, DB_USER, DB_PASSWORD, DB_NAME ); // If the 'delid' variable exists in the page link when this page is called, obtain the 'id' number of the record to be deleted and delete it. If (isset ($ _ GET ['delid']) { $ Query = "delete from toyota where id =". $ _ GET ['delid']. "LIMIT 1 "; Mysqli_query ($ dbc, $ query ); } // Locate all records and display them in the following table (if the above deletion code is executed, this is equivalent to refreshing the page) $ Query = "SELECT * FROM toyota order by id desc "; $ Data = mysqli_query ($ dbc, $ query ); // Count the number of records queried $ Count = mysqli_num_rows ($ data ); ?>
View Toyota Motor data
Title |
Source |
Vehicle model |
Main components |
Operation |
// Cyclic output list elements: title, source, carType, and majorPart. a "delete" link is added.While ($ row = mysqli_fetch_array ($ data )){Echo'
';Echo'
'. $ Row ['title'].' | ';Echo'
'. $ Row ['source'].' | ';Echo'
'. $ Row ['cartype'].' | ';Echo'
'. $ Row ['majorpart'].' | ';// Click the "delete" link to call its own page. at the same time, add the 'delid' variable on the page link and assign the value to the 'id' number of the record in the database for GETEcho'
Delete | ';Echo'
';}?>
|
...