gpt4 book ai didi

php - 在sql查询中一一增加php变量

转载 作者:行者123 更新时间:2023-11-29 20:55:41 25 4
gpt4 key购买 nike

我有一张 table 。该表有 id、name 和 sname 列。我想在 php 中运行 sql 查询。例如我的查询是

Select * from mytable where id=$n;

这里 $n 是一个变量,第一个值为 1。加载页面时,此查询正在运行。我列出了一个表查询结果。我想用 html 按钮增加 $n 值。单击按钮 $n 值必须为 2,并且查询必须使用新的 $n 变量执行。

最佳答案

您可以使用表单发布并增加 id

<?php
if (isset($_GET["increment"]) && $_GET["increment"] == 1)
$n++;

$sql = "Select * from mytable where id=$n;";

// display data as usual

?>

<form>
<input type="hidden" name="increment" value="1"/>
<button type="submit">increment</button>
</form>

关于php - 在sql查询中一一增加php变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37647739/

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