我正在尝试执行类似的操作,例如,在用户单击按钮之后,将数据存储在数据库中,然后要求该数据检查条件是否成立,如果条件满足或成立,则按钮应该消失。
存储数据成功,但是当我使用存储的数据进行检查时,if()条件错误。
这是我要使用if()检查的部分
<?
$usercheck = $conn->query("SELECT * FROM wallets WHERE wallet = $wallet ");
if($usercheck['s1'] == 0){
$res = $conn->query("SELECT * FROM shortlink WHERE shortid = 1 ");
while($row = $res->fetch_array()){
?>
<div class="col-md-2"><? echo $row['shortname']; ?></div>
<div class="col-md-2"><? echo $row['shortreward']; ?> <i class="fab fa-viacoin"></i></div>
<div class="col-md-2"><a href="shortlink.php?claim=<? echo $row['shortid']; ?>" ><button class="btn-primary" name="claim">Claim</button></a></div>
<? } } ?>
预期输出为if($ usercheck ['s3'] == 0)应该显示正确的按钮,但是if($ usercheck ['s3'] == 0)是错误的按钮不应该显示
答案 0 :(得分:0)
我在sql语句的$ wallet中添加了单个代码并执行了while循环后,问题解决了:D
<?
$usercheck = $conn->query("SELECT * FROM wallets WHERE wallet = '$wallet' ");
while($row = $usercheck->fetch_assoc()){
$s = $row['s1'];
}
if($s == 0){
$res = $conn->query("SELECT * FROM shortlink WHERE shortid = 1 ");
while($row = $res->fetch_array()){
?>
<div class="col-md-2"><? echo $row['shortname']; ?></div>
<div class="col-md-2"><? echo $row['shortreward']; ?> <i class="fab fa-viacoin"></i></div>
<div class="col-md-2"><a href="shortlink.php?claim=<? echo $row['shortid']; ?>" ><button class="btn-primary" name="claim">Claim</button></a></div>
<? } } ?>