所以我有这个:
if(isset($_GET['id'])){
$id = $_GET['id'];
$sql = "UPDATE data SET ap = 1 WHERE id = $id" ;
$retval = mysqli_query($dbcon,$sql);
$result = mysqli_query($dbcon,"SELECT ap,id FROM data WHERE id = '$id'") or die(mysql_error());
while ($row = mysqli_fetch_array($result)){
$ap = $row['ap'];
$idd = $row['id'];
}
}
和:
<div id="<?php if($ap == 1 and $idd == 1){echo:'s1p';}else{echo:'s1';}?>" class="boxabs">
</div>
<div id="<?php if($ap == 1 and $idd == 2){echo:'s2p';}else{echo:'s2';}?>" class="boxabs">
</div>
<div id="<?php if($ap == 1 and $idd == 3){echo:'s3p';}else{echo:'s3';}?>" class="boxabs">
</div>
当我将URL更改为localhost / bla / index.php?id = 3时,即使div 1具有$ ap == 1,也只有div 3显示为绿色(s1p =绿色div,sp = red div)。 此外,当我删除$ idd == x时,它们全部变为绿色。
MySQL(如果你不明白我的意思):
id|ap
1 |1
2 |2
3 |1
答案 0 :(得分:1)
我认为这是你想要达到的目标。 (未经测试)。
<?php
if(isset($_GET['id'])){
$id = $_GET['id'];
$sql = "UPDATE data SET ap = 1 WHERE id = $id" ;
$retval = mysqli_query($dbcon,$sql);
$result = mysqli_query($dbcon,"SELECT ap,id FROM data WHERE id = '$id'") or die(mysql_error());
// set a counter here
$i=1;
?>
<?php while ($row = mysqli_fetch_array($result)): ?>
<div id="<?php if($row['ap'] == 1 and $row['idd'] == 1){echo:"s$ip";}else{echo:"s$i";}?>" class="boxabs"></div>
<?php $i++; ?>
<?php endwhile; ?>