Use php in the background and reference jquery in the frontend to implement addition and deletion operations. The code is as follows:
header("Content-type: text/html; charset=utf-8");
//mysql_connect establishes a connection, mysql_close($link) closes the non-permanent connection, mysql_pconnect establishes a permanent connection
//mysql_error returns the mysql function error message, mysql_errno returns the mysql function error number
//mysql_set_charset sets the client character set, mysql_select_db selects the connection database
//mysql_query executes the query, mysql_num_rows returns the number of query records
//mysql_affected_rows returns the number of affected records, mysql_free_result releases the result set memory
//mysql_fetch_row returns enumerated array records, mysql_fetch_assoc returns associated array records
//mysql_fetch_array returns associated array or numeric array records, mysql_fetch_object returns object form records
//mysql_fetch_result obtains result set data
//%s string, %c is an ASCII character, %d is an integer, %u A symbolic number, %x a hexadecimal number
mysql_query("set charaset set utf-8");
$message=@$_POST["message"];
$shanchu=@$ _POST["shanchu"];
$top_title="PHP basic exercises";
$con=mysql_connect("localhost","root","");
//Connect to the database
mysql_set_charset ('utf-8',$con);
mysql_select_db("dbl",$con);
//Define database command query
$sql="select `message` ,`time`,` id` from message order by id desc limit 0,30";
//Execute database query
$rs=mysql_query($sql,$con);
$time=date('Y-m-d h:i :s',time());
//Get the number of items
$num_rows=mysql_num_rows($rs);//mysql_num_rows returns the number of query records
if (isset($_POST["submits"])) {
if(!$_POST["message"] ==null){
$queryinsert=sprintf("insert into message (message,time) values('%s','%s')",
$_POST['message'],$time) ;
mysql_query($queryinsert,$con);
}
if($_POST["message"]==null){
echo "";
}
header( "Location:http://localhost/table.php");
}
if(isset($_GET["ClearTd"]) && intval($_GET['ClearTd'])){
$querydelete="delete from message where id=".$_GET['ClearTd'] ;
mysql_query($querydelete,$con);
header("Location:http://localhost/table.php");
}
?>
{
?>
-
php foreach($row as $tiao){
echo $tiao;
}?>
Delete