PHP + MySql + Bootstrap allows you to delete, modify, and batch delete data on the user interface-instance operations and mysqlbootstrap
Step 1: Create the information table to be operated in the database, for example:
Step 2: delete the data in the information table
The Code is as follows: main (home page)
<! DOCTYPE html>
<Html>
<Head>
<Meta charset = "UTF-8">
<Title> delete function </title>
<Script src = "bootstrap/js/jquery-1.11.2.min.js"> </script> // introduce the three files
<Script src = "bootstrap/js/bootstrap. min. js"> </script>
<Link href = "bootstrap/css/bootstrap.min.css" rel = "stylesheet" type = "text/css"/>
</Head>
<Body>
<Div> // use form to submit the page
<Table class = "table-hover"> // prevents incorrect operations
<Button type = 'button 'class = 'btn btn-primary btn-xs '> Delete </button>
</A>
<A href = 'Update _ page. php? Code = {$ v [0]} 'onclick = \ "return confirm ('Are you sure you want to modify it? ') \ ">
<Button type = 'button 'class = 'btn btn-primary btn-xs '> modify </button>
</A>
</Td>
</Tr> ";
}
?>
</Tbody>
</Table>
<Button type = "submit" class = "btn-danger btn-xs"> // The JS operation here is the Click Event of the batch selection button for Step 4 batch deletion (same step 4)
<Script>
Function qx (qx ){
Var ck = document. getElementsByClassName ("ck ");
For (var I = 0; I <ck. length; I ++ ){
Ck [I]. checked = qx. checked;
}
}
</Script>
</Html>
Delete (delete processing page)
<? Php
$ Code = $ _ GET ["code"];
$ Db = new MYSQLi ("localhost", "root", "", "0710_info ");
$ SQL = "delete from fruit where ids = '{$ code }'";
If ($ db-> query ($ SQL )){
Header ("location: del_page.php ");
} Else {
Echo "failed to delete! ";
}
Step 3: implement the database data modification function (connected to the main interface)
The Code is as follows:
<! DOCTYPE html>
<Html>
<Head>
<Meta charset = "UTF-8">
<Title> modification </title>
<Script src = "bootstrap/js/jquery-1.11.2.min.js"> </script>
<Script src = "bootstrap/js/bootstrap. min. js"> </script>
<Link href = "bootstrap/css/bootstrap.min.css" rel = "stylesheet" type = "text/css"/>
</Head>
<Style>
*{
Margin: 0px auto;
Padding :;
}
. Input-group {
Margin-top: 15px;
}
. Sub {
Margin: 20px 260px 10px;
}
</Style>
<Body>
<Div>Update (modify processing page)
<? Php
$ Code = $ _ POST ["code"];
$ Name = $ _ POST ["name"];
$ Price = $ _ POST ["price"];
$ Chandi = $ _ POST ["chandi"];
$ Kucun = $ _ POST ["kucun"];
$ Db = new MYSQLi ("localhost", "root", "", "0710_info ");
$ SQL = "update fruit set
Name = '{$ name}', price = {$ price}, source = '{$ chandi }', numbers = {$ kucun} where ids = '{$ code }'";
If ($ db-> query ($ SQL )){
Header ("location: del_page.php ");
} Else {
Echo "failed to modify! ";
}
Step 4: implement the batch selection and deletion of data in the database (connected to the main interface)
The JS operation code is as follows:
<Script>
Function qx (qx ){
Var ck = document. getElementsByClassName ("ck ");
For (var I = 0; I <ck. length; I ++ ){
Ck [I]. checked = qx. checked;
}
}
</Script>
The PHP operation code is as follows:
<? Php
$ Arr = $ _ POST ["sub"];
Require_once "./DBDA. class. php"; // load the class to enter the operation interface.
$ Db = new DBDA ();
$ Str = implode ("','", $ arr );
$ SQL = "delete from fruit where ids in ('{$ str }')";
If ($ db-> query ($ SQL, 1 )){
Header ("location: del_page.php ");
} Else {
Echo "failed to delete! ";
}
* ** Here, the data volume class is encapsulated (optimized for use)
The PHP code is as follows:
<? Php
Class DBDA {
Public $ host = "localhost ";
Public $ uid = "root ";
Public $ pwd = "";
Public $ dbname = "0710_info ";
/*
Query Method: Execute the SQL statement given by the user and return the corresponding result.
$ SQL: SQL statement to be executed
$ Type: type of the SQL statement to be executed
Return: returns true or false if it is an added or deleted statement, and returns a two-dimensional array if it is a query statement.
*/
Public function query ($ SQL, $ type = 1) {// by default, "true" indicates addition, deletion, and modification.
$ Db = new MySQLi ($ this-> host, $ this-> uid, $ this-> pwd, $ this-> dbname );
If (mysqli_connect_error ()){
Return "connection failed! ";
}
$ Result = $ db-> query ($ SQL );
If ($ type = 1 ){
Return $ result; // The add, delete, and modify statements return true or false.
} Else {
Return $ result-> fetch_all (); // the query statement returns a two-dimensional array.
}
}
}