Function:
1, on a page to display query data, and after each data added delete function, click "Delete", delete the data, while refreshing the page
2, get the way to obtain the deletion conditions
Database connection Variable connectvars.php
Copy Code code as follows:
<?php
Server
Define (' db_host ', ' localhost ');
User name
Define (' Db_user ', ' root ');
Password
Define (' Db_password ', ' root ');
Database
Define (' db_name ', ' test ');
?>
Record Display page display.php, after each record has "delete" function, click "Delete", can delete this record, simultaneously refresh the page
Copy Code code as follows:
<?php
Require_once ' connectvars.php ';
$DBC = Mysqli_connect (db_host,db_user,db_password,db_name);
If you call this page with the ' delid ' variable in the page link, get the ' ID ' number of the record you want to delete 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 next table (if the deletion code above 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 record bars queried
$count = Mysqli_num_rows ($data);
?>
<title> Toyota Auto Data View </title>
<body>
<table>
<!--table column name-->
<tr>
<th> title </th>
<th> sources </th>
<th> Models </th>
<th> Main parts </th>
<th> Operations </th>
</tr>
<?php
Loop output list elements: Title, source, Cartype, Majorpart, and then add a "delete" link
while ($row = Mysqli_fetch_array ($data)) {
Echo ' <tr> ';
echo ' <td><a href = '. $row [' url ']. ' > '. $row [' title ']. ' </td> ';
Echo ' <td> '. $row [' source ']. ' </td> ';
Echo ' <td> ' $row [' Cartype ']. </td> ';
Echo ' <td> ' $row [' Majorpart ']. </td> ';
Click on the "delete" link to call its own page, while adding ' delid ' variables to the page link, assigning the ' ID ' number of the record in the database to get
echo ' <td><a href = '. $_server[' php_self '. Delid= '. $row [' ID ']. ' " > Delete </a></td> ';
Echo ' </tr> ';
}
?>
</table>
</body>