douhuang4166 2013-01-23 05:09
浏览 18
已采纳

无法在列表菜单中放置特定值

I have a playlist and a player in one script. When click any one of the list it passes a value which i take with GET method($_GET['List_id']) and then play this specific video. But i need a highlighter to highlight the list item which is playing now. In twitter bootstrap it needs only to declare class='active'. So i initialize class blank($ive = '') and when it matches with $_GET values it put active into it. But it won't works, With this code all list items show active. How to put this 'active' within $ive variable?

Here is my code--

<?php
include "ste_content/connect.php";

//initialize
$subID = $_GET['Subcategory_id'];
$listID = $_GET['List_id'];
$list = "";
$ive = '';

$strSQL = "SELECT * FROM `video_links` WHERE `Subcategory_id`=".       
    $_GET["Subcategory_id"] ." ORDER BY `Subcategory_id`";
$rs = mysql_query($strSQL);

while($row = mysql_fetch_array($rs)) {
    $strTitle = $row['List_title'];
    $id = $row['List_id'];

    $strLink = "<a href = 'tv.php?List_id=" . $row['List_id'] 
        . "&&Subcategory_id=". $row['Subcategory_id']."'>" 
        . $strTitle . "</a>";

    if(strcmp($listID,$id)==0){
        $ive = 'active';
    }

    $list .= "<li class='$ive'><a href='#'><i class='icon-chevron-right'></i> $strLink </a></li>" ;  
}

mysql_close();
?>

I am output this $list variable inside html.

  • 写回答

2条回答 默认 最新

  • duanmengmiezen8855 2013-01-23 05:18
    关注

    You need to reset the $ive variable in each loop or else everything after the first match will be active.

    Try this

    $list .= sprintf('<li%s><i class="icon-chevron-right"></i> %s </li>',
                     $id == $listID ? ' class="active"' : '', $strLink);
    

    Also, you seem to be nesting <a> tags with $strLink in $list. You probably don't want to do that

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 有没有帮写代码做实验仿真的
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥30 vmware exsi重置后登不上
  • ¥15 易盾点选的cb参数怎么解啊
  • ¥15 MATLAB运行显示错误,如何解决?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题