我在一个小项目中工作,在 excel 中读取一些数据文件,所以我将数据放入 MySQL 数据库中,然后在 php 文件中读取它,这样它就很容易读写,我将它放在分页页面中以便于在行之间传输trey 在 php 文件中制作一些代码作为我的一点经验,它工作正常并从数据库读取数据并更新它但是问题是当我按下更新按钮时它再次返回到第一页例如当我在页面中时4 然后按更新,他将数据发送到数据库,但他又将我返回到第一页
<?php
include('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";
}
}
?>
郎朗坤
四季花海
随时随地看视频慕课网APP