The little woman ask for advice, how to delete the corresponding record in the database when you click on a record in a table in the PHP Web page

Source: Internet
Author: User
How do you delete a record from a database when you click on a table in a PHP page?
For example, PHP is written in a Web page similar to the following table:

Ordinal name Sex Delete edit
1 Three men Delete edit
2 Lee four girls delete edit

Among them, the serial number, name, gender, etc. are read directly from the database.

How do I remove the entire record with the sequence number 1 from the database when I click "Delete" with serial number 1?
(delete is in href format, link to processing page.) )

You want to get the serial number by clicking "Delete" and then passing it through the form post to the processing page,
The database is manipulated by the processing page.
But I don't know how to get this serial number. ~~~~~~~~~~
Thank you, great God.

------to solve the idea----------------------
This has to use JS to get the serial number and then assign the value to a field in the form of a post to operate.
If it's a delete, it can be done by Ajax. This avoids the entire page being refreshed when the form is submitted
------to solve the idea----------------------
Can't find the row?
Ordinal name Sex Delete edit
1 Three men Delete edit
2 Lee four girls delete edit

So how do you read these records? Read the code to see
------to solve the idea----------------------

Execute SQL
$sql = "SELECT * from users";
Execute Query
$result = mysql_query ($sql);

Results
See Mysql_result (), mysql_fetch_array (), mysql_fetch_row (), etc.
while ($row = Mysql_fetch_assoc ($result)) {
echo $row [' serial number '];
echo $row [' name '];
echo $row [' Gender '];
echo ' delete ';
}

Releasing resources for the associated result set
It will be done automatically at the end of the script.
Mysql_free_result ($result);
?>



Replace the field of the database with the ordinal name gender

------to solve the idea----------------------
Just a moment ago wrote a, for you to refer to the next





































































/* Output */$sql = "SELECT count (*) from blog";$rs = $con->query ($sql);$row = $rs->fetch_array ();$num = $row [0];//Total article number$recordnum = 8; Number of articles displayed per page$pages = Ceil ($num/$recordnum);//Total pagesif ($_get[' id '){if ($_get[' id ']==1) {$current = 1;//Current page$pre = 1;//Previous page$next = 2;//Page}else if ($_get[' id ']>1) {$pre = $_get[' id ']-1;$current =$_get[' id '];$next =$_get[' id ']+1;}} else{Null value$current = 1;$pre = 1;$next = 2;}SQL If there are operations that need to be listed separately$sql = "Select Blog.id as blogID, Blog.title,blog.content,blog.keywords,blog.listid,blog.userid,blog.ctime,blog.yes, Blog.del,list.id,listtitle from Blog,list where Blog.del <> ' 1 ' and Blog.listid = list.id ORDER BY blog.id Desc Limi T ". ($current-1) * $recordnum. ", $recordnum";$rs = $con->query ($sql);while ($row = $rs->fetch_assoc ()){$newdate = Date ("y-m-d", Strtotime ($row [' CTime ']));Echo" ";}?>
Title Column Creation time Top Delete
". $row [' title ']." ". $row [' ListTitle ']." ". $newdate." Black Rain Delete

------to solve the idea----------------------
The > Delete

1. Remove extra spaces and quotes from the URL
2, value with $_get[' ID '], not $_post[' id ']
3, if you really want to use the Post method. That can use Ajax
  • 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.