This article introduces a simple method to refresh the current page when deleting database records. this method is not implemented by ajax but refreshed by get. this method is used in practical applications.
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, the user experience of this method is not good in practical applications. let's take a look at this method.
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
-
-
-
- While ($ row = mysqli_fetch_array ($ data )){
- Echo'
- Echo'
- Echo'
- Echo'
- Echo'
- // 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 GET
- Echo'
- Echo'
- }
- ?>
- // Cyclic output list elements: title, source, carType, and majorPart. a "delete" link is added.
| Title |
Source |
Vehicle model |
Main components |
Operation |
';
| . $ Row ['URL']. '>'. $ row ['title'].' | ';
'. $ Row ['source'].' | ';
'. $ Row ['cartype'].' | ';
'. $ Row ['majorpart'].' | ';
. $ _ SERVER ['php _ SELF '].'? DelID = '. $ row ['id'].' "> Delete | ';
';
-
-