Php and mysql delete specified employee information

Source: Internet
Author: User
Tags mysql delete
Submit the employee ID to mysql using php, and then mysql accepts the data and uses delete to delete the data. I will share with you several examples below. example of the delete statement: deletefromfriendsw... submit the employee ID to mysql using php, and then mysql accepts the data and uses delete to delete the data. I will share with you several examples below.

Example of a delete statement:

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:

    
 
  
Employee info table
  
 
  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']); // delete the employee information of the specified id} if (isset ($ _ SESSION ['arr']) {foreach ($ _ SESSION ['arr'] as $ k => $ v) {echo" 
   ";}}?> 
  
No. Name Age
". ($ 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:

 "; // Output the name of the employee to be deleted // open-source code phprm.com $ B ++ }}}?>

(2) store the file in the MR 2 66 folder and name it index. php.


Permanent address:

Reprint at will ~ Please bring the tutorial URL ^

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.