开发者

Problem with foreach loop and $_GET

开发者 https://www.devze.com 2023-01-02 17:17 出处:网络
I have a very simple foreach loop foreach($tv as $id => $channel) { $ID = $_GET[\'ID\']; if($ID == $id){$class = \"currentt\";}

I have a very simple foreach loop

foreach($tv as $id => $channel) {
$ID = $_GET['ID'];
if($ID == $id){$class = "currentt";}
echo '<a href="http:开发者_如何学编程//www.mysite.com/tst.php?ID='.$id.'"     class="'.$class.'">'.$channel.'</a><br>';
 }

With url query, with every click the current class repeated. How can avoid this? Thanks alot.


$ID = $_GET['ID'];
foreach($tv as $id => $channel) {
    $class = $ID == $id ? "currentt": '';
    echo "<a href='http://www.mysite.com/tst.php?ID=$id' class='$class'>$channel</a><br>";
}

The problem you had was that you never change $class after it was assigned value 'currentt'.

0

精彩评论

暂无评论...
验证码 换一张
取 消