我有一个页面,其中从单个表中显示多个表单,相同的表单但不同的值带有一些输入和每个表单的最后一个按钮。
当特定值返回特定数量时,有什么方法可以禁用特定表单的按钮?
就像我通过 foreach 循环从表中获取数据以显示在页面上一样:
$userID = $_SESSION['username']['UserID'];
$query = "Select * from tbl_packages";
$result = mysqli_query($conn,$query);
$num = mysqli_num_rows($result);
mysqli_close($conn);
foreach($result as $data):
$PkgID = $data['id'];
$PkgAmount = $data['amount'];
$PkgFees = $data['fees'];
$PkgPeriod = $data['period'];
$ReturningAmount = $data['returnAmount'];
?>
<form
action=""
class="form-inline"
method="POST"
id="buyPackage-init"
>
<input
class="form-control form-control-user"
name="PkgID"
id="PackagegID"
value=<?php echo $PkgID?>
readonly
>
<!-- and more inputs like above... -->
</form>
<?PHP
endforeach;
?>
然后我从第二个表中选择存储的表单值,以检查表单数据是否已经存在于循环中的表中,如下所示:
$queryCheckPackage = "select status from tbl_lendinglogs where UserID = '$userID'";
$resultCheckPackage = mysqli_query($conn,$queryCheckPackage);
$numCheckPackage = mysqli_num_rows($resultCheckPackage);
$FetchCheckPackage = mysqli_fetch_array($resultCheckPackage);
$value = null;
foreach($resultCheckPackage as $row)
{
if($row['status'] == 1) {
//echo $row['status'];
$value = "disabled";
} else {
$value = "enabled";
//echo "enabled <BR>";
}
}
mysqli_close($conn);
然后是标签前表单中的按钮:
<input
class="btn btn-primary btn-user btn-block"
onclick="return confirm('Confirm befor buy?');"
type="submit"
id="btn"
data-target="#buyPackage"
value="Invest"
name="bttn-order"
<?php echo $value ?>
/>
现在发生的事情是所有按钮都被禁用,而表中存储了两个表单 1 表单数据状态为 0,第二个状态为 1。我想检查所有状态,然后禁用状态为 1 的特定表单按钮存储的表单表。
有没有可能这样做?通过在互联网上长时间挖掘有关此信息的信息,我感到很糟糕。我自己尝试了很多,但它禁用了所有按钮,而在循环中有两个状态值是“0”和“1”。
<------------------------更新并解决了问题----------------->
这是带有 foreach 循环的查询
$userID = $_SESSION['username']['UserID'];
$query = "Select * from tbl_packages";
$result = mysqli_query($conn,$query);
$num = mysqli_num_rows($result);
//$buttons = [];
$pkgStatus = null;
$PkgID = 0;
foreach($result as $data):
$PkgID = $data['id'];
$PkgAmount = $data['amount'];
$PkgFees = $data['fees'];
$PkgPeriod = $data['period'];
$ReturningAmount = $data['returnAmount'];
$queryCheckPackage = "select * from tbl_lendinglogs where UserID = '$userID' and pkg_id = '$PkgID'";
$resultCheckPackage = mysqli_query($conn,$queryCheckPackage);
$numCheckPackage = mysqli_num_rows($resultCheckPackage);
$FetchCheckPackage = mysqli_fetch_array($resultCheckPackage);
foreach($resultCheckPackage as $row):
$pkgStatus = $row['status'];
?>
这是按钮:
<input class="btn btn-primary btn-user btn-block" onclick="return confirm('Confirm befor buy?');" type="submit" id="btn" data-target="#buyPackage" value="Invest" name="bttn-order" <?php if ($pkgStatus == 1) echo 'disabled="disabled"' ?>/>
然后我在末尾为每个添加了 end :
<?php endforeach; endforeach;?>
非常感谢@Wimanicesir,您帮了很多忙。