News list display, delete function PHP code
<?php session_start(); header("content-type:text/html;charset=utf-8"); //連接數(shù)據(jù)庫 $link = mysqli_connect("localhost","root","root","news"); mysqli_set_charset($link,"utf8"); if (!$link) { die("連接失敗: " . mysqli_connect_error()); } //連接數(shù)據(jù)庫 $SQL = "SELECT * FROM NEW";//設(shè)置查詢指令 $result=mysqli_query($link,$SQL);//執(zhí)行查詢 $idD = isset($_GET['idD'])?$_GET['idD']:''; if($idD){ $sqlD = "delete from new where id = {$idD}"; $result = mysqli_query($link, $sqlD); if($result){ echo "<script>alert('刪除成功');window.location.href='lists.php'</script>"; }else{ echo "<script>alert('操作錯誤');window.location.href='lists.php'</script>"; } } ?>
The above code is all the code to delete the display. Simply put, it is the operation of the database.
Many people will wonder why there are no codes displayed in the list, but only deleted ones. In the previous section, we talked about a loop statement. In fact, that loop has already displayed the database data on the list page.
First connect to the database, execute a query on the database, and pass the obtained value to the front-end page. Next is deletion, executing the statement to delete the database.