Php + mysql deletes employee information of a specified number. Php + mysql how to delete employee information with specified number this article mainly introduces how to delete employee information with specified number in php + mysql, involving mysql database operation skills, you can refer to the methods used to delete employee information of a specified number in php + mysql.
This article describes how to delete the employee information of a specified number in php + mysql. it involves mysql database operation skills and has some reference value. For more information, see
This example describes how to delete employee information of a specified number in php + mysql. Share it with you for your reference. The specific analysis is as follows:
Submit the employee ID to mysql using php, and then mysql accepts the data and uses delete to delete the data. here we will share with you a few examples.
Example of a delete statement:
The code is as follows:
Delete from friends where user_name = 'simaopig ';
In the syntax structure, we can see that, like the update syntax, we can omit the where clause, but this is a very dangerous behavior, because if you do not specify the where clause, delete deletes all records in the table and deletes them immediately.
1. delete the employee information of the specified number. the code is as follows:
The code is as follows:
Employee info table
No. |
Name |
Age |
Header ("Content-type: text/html; charset = utf-8 ");$ _ SESSION ['arr'] = array ('1' => array ('name' => 'Zhang San', 'age' => 18 ), '2' => array ('name' => 'Li Si', 'age' => 19), '3' => array ('name' => 'Wang 5 ', 'age' => 20 ));If (! Emptyempty ($ _ POST ['num']) {Unset ($ _ SESSION ['arr'] [$ _ POST ['num']); // deletes the employee information of a specified id}If (isset ($ _ SESSION ['arr']) {Foreach ($ _ SESSION ['arr'] as $ k => $ v ){Echo"
". ($ K )." |
". $ V ['name']." |
". $ V ['age']." |
";}}?>
2. example of batch deletion of employee information
Key technology: the key point of this instance is the flexible use of the while () loop statement. execute the while () loop statement based on the submitted parameter value and delete the loop weight, the data is deleted cyclically.
Design process:
(1) create a PHP script file. first, connect to the MySQL database server, connect to the database named db_while in MySQL, and set the page encoding format. then, define the variable variables $ a and $ B, set the condition of the loop in the 1st-layer while loop to $ B <$ a, and then use the while statement to output the data in the data table again, and execute the data deletion operation. the code is as follows:
The code is as follows:
If ($ _ POST [sub]) {// Obtain parameters through POST
$ Conn = mysql_connect ("localhost", "root", "111"); // connect to the mysql database
Mysql_select_db ("db_while", $ conn); // connect to the database
Mysql_query ("set names gbk"); // defines the encoding format
$ A = $ _ POST [te]; // receives text box parameters
$ B = 0; // define the variable
While ($ B <$ a) {// while loop
$ Rs = mysql_query ("select * from tb_while"); // execute the query operation
While ($ rst = mysql_fetch_array ($ rs) {// Save the query results in the array
$ SQL = "delete * from tb_while where id = $ B"; // SQL statement
Mysql_query ($ SQL); // execute the delete operation
The employee whose echo "name is". $ rst [name]. "has been deleted
"; // Output the name of the employee to be deleted
$ B ++
}
}
}
?>
(2) store the file in the MR 2 66 folder and name it index. php.
I hope this article will help you design the php + mysql program.
This article describes how to delete employee information of a specified number in php + mysql. it involves mysql database operation skills and provides some reference...