3 回答
TA贡献1829条经验 获得超7个赞
反映数据库中的变化。尝试在数据库中创建 bool 列并尝试使用 ajax 在数据库中更改它
<script>
$('.add').click(function() {
this.value = 'Continue shopping';
$.ajax({
type: "POST",
url: "currentfilename.php",
data: {change:'true'},
});
});
</script>
PHP文件
if(isset($_POST['change']))
{
$connection= mysqli_connect("localhost","my_user","my_password","my_db");
$sql="update tablename set colname=1";
mysqli_query($connection,$sql);
}
HTML文件写入选择查询并获取列并写入以下内容
if($row['col']==1)
{echo"<button type='button'>Continue shopping</button>
}
TA贡献1872条经验 获得超3个赞
这是一个解释一切的教程。你没有要求每次看到教程,但它是一个很好的阅读。https://phppot.com/php/simple-php-shopping-cart/
TA贡献1847条经验 获得超11个赞
从数据库和视图文件中获取值。
<?php
$htmlResponse = "";
//by which column values you want change button text check condition for that.
if ($data->column_name == 0) {
$htmlResponse .= '<span onclick="changeActivityStatus(' . $data->id . ', 1, this)" style="cursor: pointer;">add to cart</span>';
}
else {
$htmlResponse .= '<span onclick="changeButton(' . $data->id . ', 0, this)" data-value="Blocked" style="cursor: pointer;">Continue shopping</span>';
}
?>
<?php echo $htmlResponse; ?>
call function in js file
//test.php file is just an example you put here your php file name
function changeButton(id, status) {
$.post(base_url + "test.php", {id: id, status: status}, function (data) {
if (data.code === "1") {
alert('success');
window.location.reload();
} else if (data.code === "0") {
alert('something went wrong');
}
});
}
在 test.php 中,如果单击添加到购物车按钮值将更新并且按钮文本将更改,则您必须使用更新查询
- 3 回答
- 0 关注
- 230 浏览
添加回答
举报