Php+mysql+bootstrap implementation of user interface data deletion, modification and bulk selection Delete--instance operation

Source: Internet
Author: User

The first step: Create a table of information to manipulate in the database such as:

Step two: Implement the Delete function of the data in this information table

The code is as follows: Main (Main Page)

<! DOCTYPE html>
<meta charset= "UTF-8" >
<title> Delete Features </title>
<script src= "Bootstrap/js/jquery-1.11.2.min.js" ></script>//Introduction of three files here
<script src= "Bootstrap/js/bootstrap.min.js" ></script>
<link href= "Bootstrap/css/bootstrap.min.css" rel= "stylesheet" type= "Text/css"/>
<body>
<div style= "height:100px;" ></div>
<form action= "batch_process.php" method= "POST" >//Use form form to submit page
<table class= "Table Table-hover" style= "max-width:800px;margin-left:260px;" >
<thead>
<tr>
<th><input type= "checkbox" onclick= "QX (This)"/>&nbsp;&nbsp;&nbsp; code </th>
<th> name </th>
<th> Price </th>
<th> Origin </th>
<th> Inventory </th>
<th> Operations </th>
</tr>
</thead>
<tbody>
<?php
$db = new Mysqli ("localhost", "root", "" "," 0710_info ");
$sql = "SELECT * from Fruit";
$result = $db->query ($sql);
$arr = $result->fetch_all ();

foreach ($arr as $v) {
echo "<tr>
<td><input type= ' checkbox ' class= ' ck ' value= ' {$v [0]} ' name= ' sub[] '/>&nbsp;&nbsp;&nbsp; {$v [0]}</td>
<td>{$v [1]}</td>
<td>{$v [2]}</td>
<td>{$v [3]}</td>
<td>{$v [4]}</td>
<td>
<a href= ' del_processpage.php?code={$v [0]} ' onclick=\ ' return confirm (' OK delete? ') \ ">//Prevent error handling
<button type= ' button ' class= ' btn btn-primary btn-xs ' > Delete </button>
</a>
<a href= ' update_page.php?code={$v [0]} ' onclick=\ ' return confirm (' OK to modify? ') \ ">
<button type= ' button ' class= ' btn btn-primary btn-xs ' > Modify </button>
</a>
</td>
</tr> ";
}
?>
</tbody>
</table>
<button type= "Submit" class= "btn btn-danger btn-xs" style= "margin-left:260px;" > Bulk Delete </button>
</form>
</body>

 Here the JS operation for the fourth Step bulk Delete Batch selection button click event Action (same as the fourth step)
<script>
function QX (QX) {
var ck = document.getelementsbyclassname ("ck");
for (Var i=0;i<ck.length;i++) {
ck[i].checked=qx.checked;
}
}
</script>

Delete (remove 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 "Delete failed!";
}

Step three: Implement the modification of the data in the database (connect with the main interface)

The code is as follows:

<! DOCTYPE html>
<meta charset= "UTF-8" >
<title> Modify Features </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"/>
<style>
*{
margin:0px Auto;
padding:;
}
. input-group{
margin-top:15px;
}
. sub{
margin:20px 260px 10px;
}
</style>

<body>
<div style= "height:100px;" ></div>
<?php
$code = $_get["code"];
$db = new Mysqli ("localhost", "root", "" "," 0710_info ");
$sql = "SELECT * from fruit where ids= ' {$code} '";
$result = $db->query ($sql);
$arr = $result->fetch_row ();
?>
<form action= "update_processpage.php" method= "POST" >
<div class= "Panel Panel-default" style= "max-width:600px;" >
<div class= "Panel-heading" >
modifying data
</div>
<div class= "Panel-body" >
<div class= "Input-group" >
<span class= "Input-group-addon" > Code </span>
<input type= "text" class= "Form-control" readonly= "readonly" placeholder= "Please enter code" name= "code" value= "<?php echo $ Arr[0]?> ">
</div>
<div class= "Input-group" >
<span class= "Input-group-addon" > Name </span>
<input type= "text" class= "Form-control" placeholder= "Please enter name" name= "name" value= "<?php echo $arr [1]?>" >
</div>
<div class= "Input-group" >
<span class= "Input-group-addon" > Price </span>
<input type= "text" class= "Form-control" placeholder= "Please enter prices" name= "price" value= "<?php echo $arr [2]?>" >
</div>
<div class= "Input-group" >
<span class= "Input-group-addon" > Origin </span>
<input type= "text" class= "Form-control" placeholder= "Please enter origin" Name= "Chandi" value= "<?php echo $arr [3]?>" >
</div>
<div class= "Input-group" >
<span class= "Input-group-addon" > Stock </span>
<input type= "text" class= "Form-control" placeholder= "Please enter inventory" name= "Kucun" value= "<?php echo $arr [4]?>" >
</div>
<button type= "Submit" class= "BTN btn-primary Sub" > Submit </button>
</div>
</div>
</form>
</body>

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 "Modification failed!";
}

Fourth step: Implement the bulk selection and deletion of data in the database (connected to the main interface)

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 class into the operator 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 "Delete failed!";
}

This is where the data access 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: Executes the user-given SQL statement and returns the corresponding result
$SQL: SQL statement that the user needs to execute
$type: The type of SQL statement that the user needs to execute
Return: If the deletion statement returns TRUE or FALSE, if the query statement returns a two-dimensional array
*/
Public Function query ($sql, $type =1) {//default true for additions and deletions
$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;//Change the statement to return TRUE or false
}else{
return $result->fetch_all ();//query statement returns a two-dimensional array
}
}
}

Php+mysql+bootstrap implementation of user interface data deletion, modification and bulk selection Delete--instance operation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.