Functions:
1. Display 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 to obtain deletion conditions
Database connection variables connectvars.php
Copy code The code is as follows:
//Server
define('DB_HOST', 'localhost');
//Username
define('DB_USER', 'root');
//Password
define('DB_PASSWORD', 'root');
//Database
define('DB_NAME','test');
?>
Record display page display.php, each record There is a "Delete" function at the end. Click "Delete" to delete the record and refresh the page at the same time
Copy the code The code is as follows:
require_once 'connectvars.php';
$dbc = mysqli_connect(DB_HOST,DB_USER,DB_PASSWORD,DB_NAME);
//If there is ' in the page link when calling this page DelID' variable, get 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);
}
//Find all records and display them in the next table (if the above The deletion code is executed, which is equivalent to refreshing the page)
$query = "SELECT * FROM toyota ORDER BY ID DESC";
$data = mysqli_query($dbc,$query);
// Count the number of queried records
$count = mysqli_num_rows($data);
?>
Toyota car data View
Title |
Source |
Model |
Main components< /th>
| Operation |
//Loop output list elements: title, source, carType, majorPart, and then Add a "delete" link
while($row = mysqli_fetch_array($data)){
echo '';
echo ''.$row['title'].' | ';
echo ''.$row['source'].' td>'; echo ' | '.$row['carType'].' | ';
echo ''.$row['majorPart']. ' | ';
//Click the "Delete" link to call your own page. At the same time, add the 'DelID' variable to the page link and assign it the 'ID' number recorded in the database for GET Get
echo 'Delete'; echo ' |
';
}
?>
< ;/html>
http://www.bkjia.com/PHPjc/324753.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/324753.htmlTechArticleFunction: 1. Display query data on a certain page, and add a delete function after each piece of data, click "Delete", delete the data and refresh the page at the same time. 2. Use GET method to obtain the deletion item...