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
| Title |
Column |
Creation time |
Top |
Delete |
/* 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"
| ". $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