亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

當在分頁頁面中按更新時,我會再次回到第一個頁面

當在分頁頁面中按更新時,我會再次回到第一個頁面

PHP
郎朗坤 2022-12-11 19:15:41
我在一個小項目中工作,在 excel 中讀取一些數據文件,所以我將數據放入 MySQL 數據庫中,然后在 php 文件中讀取它,這樣它就很容易讀寫,我將它放在分頁頁面中以便于在行之間傳輸trey 在 php 文件中制作一些代碼作為我的一點經驗,它工作正常并從數據庫讀取數據并更新它但是問題是當我按下更新按鈕時它再次返回到第一頁例如當我在頁面中時4 然后按更新,他將數據發送到數據庫,但他又將我返回到第一頁<?phpinclude('db.php');if (isset($_GET['page_no']) && $_GET['page_no']!="") {    $page_no = $_GET['page_no'];    } else {        $page_no = 1;        }    $total_records_per_page = 3;    $offset = ($page_no-1) * $total_records_per_page;    $previous_page = $page_no - 1;    $next_page = $page_no + 1;    $adjacents = "2";     $result_count = mysqli_query($con,"SELECT COUNT(*) As total_records FROM `b_2011`");    $total_records = mysqli_fetch_array($result_count);    $total_records = $total_records['total_records'];    $total_no_of_pages = ceil($total_records / $total_records_per_page);    $second_last = $total_no_of_pages - 1; // total page minus 1            $result = mysqli_query($con,"SELECT * FROM `b_2011` LIMIT $offset, $total_records_per_page");    while($row = mysqli_fetch_array($result)){        echo"<form method=post  action=index.php>";     echo "<tr>     <td>"."<input type=text name=id value=".$row['id']." </td>     <td>".$row['details_all']."</td>     <td>"."<input type=text name=Class_send value=".$row['classfication']." </td>     <td>" ."<input type=text name=det_send value=".$row['details']." </td>     <td>" ."<input type=submit name=update value= update .</td>     </tr>";        echo "</form>";        }        if (isset($_POST['update'])){    $ID=$_POST['id'];    $classsication=$_POST['Class_send'];    $details=$_POST['det_send'];    if (mysqli_query($con,"UPDATE b_2011 SET classfication='".$classsication."',details='".$details."' WHERE id=".$ID))    {        echo "records updates";    }    }        ?>
查看完整描述

1 回答

?
四季花海

TA貢獻1811條經驗 獲得超5個贊

計算項目將顯示的頁面并在更新后重定向到該頁面:


您已經從 獲得了 id $ID=$_POST['id'];,讓我們找到它的位置:


// Execute query, searching for id less or equal than the ID you've got previously

$result = mysqli_query($con,"SELECT COUNT(*) FROM `b_2011` WHERE id <= $ID");

// This query will return just 1 row with 1 value

$row = mysqli_fetch_row($result);

// First item holds the counter

$records = $row[0];


// Get page number to go

$page = ($records == 0) ? 1 : ceil($records / $total_records_per_page);


// Redirect to the page

header("Location: index.php?page_no=$page");

// End the script

exit;

順便說一下,你的腳本有被攻擊的風險,請考慮使用準備好的語句,你可以從我如何防止用 PHP 進行 SQL 注入?


查看完整回答
反對 回復 2022-12-11
  • 1 回答
  • 0 關注
  • 166 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號