开发者

Problem with foreach loop and $_GET

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜