gpt4 book ai didi

mysql - 更新后..不刷新页面

转载 作者:行者123 更新时间:2023-11-30 00:23:16 25 4
gpt4 key购买 nike

在 pagination.php 页面中,我有代码允许我通过使用 ajax 单击链接将每行中的文本从“激活”更改为“停用”或“停用”更改为“激活”,它将自动更新到 mysql 数据库然后刷新到pagination.php中的第一页...

请查看代码...

在 pagination.php jquery 代码中......

$.ajax({
type: "GET",
url: "action.php",
data: { status: "<?php echo $_GET['pid'];?>" }
})

在action.php代码中...

<?php 
include('db.php');
if(isset($_GET['status']))
{
$status1=$_GET['status'];
$select=mysql_query("select * from product where product_id='$status1'");
while($row=mysql_fetch_object($select))
{
$status_var=$row->status;
if($status_var=='0')
{
$status_state=1;
}
else
{
$status_state=0;
}
$update=mysql_query("update product set status='$status_state' where product_id='$status1' ");
if($update)
{
header("Location: pagination.php");
}
else
{
echo mysql_error();
}
}
?>
<?php
}
?>

这些代码效果很好,但问题是在 pagination.php 中,如果我在第二页或任何其他页面,当我更改文本链接时,它将刷新 pagination.php 页面回到第一页,我的问题是如何通过更改链接后不刷新页面并保持在同一页面来解决!

最佳答案

header("Location: pagination.php");

第一页上的这个重定向 - pagination.php。试试这个

header("Location: pagination.php".($_GET['page'] ? '?page='.$_GET['page']:''));

关于mysql - 更新后..不刷新页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23067644/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com