1

我有这个 php 代码

    <div id="offers-menu">      
   <?php
   function custom_get_categories_options($rootid = 0,$selected = false,$ident = 0) {
    $db = Bux::getDbInstance();
    $q = $db->query("SELECT * FROM ".clix_offers::$table['categories']." WHERE parent_id = ".(int)$rootid);
    $str = '';
    $ident++;
    while($row = $db->fetchAll($q)) {

      $str .= '<li '.(($_GET['cat_id'] == $row['id']) ? ' class="selected"':'' ).' ><a href="?cat_id='.$row['id'].'">'.$row['name'].'</a>';
      $str .= custom_get_categories_options($row['id'],$selected,$ident);
      $str .= '</li>';
    }

    if($str != "") return $ident>0?"<ol>{$str}</ol>":"{$str}";
   }
   ?>       

        <ul>
            <li <?php echo (!isset($_GET['cat_id']) || $_GET['cat_id'] == "all")?' class="selected" ':'';?>><a href="?cat_id=all">All Admin Offers</a></li>
                <?=custom_get_categories_options();?>

        </ul>

    </div>

输出将是这样的

在此处输入图像描述

我想为此菜单使用 HTML 选择标签

就像是

<select>
  <option value="1">Advertisers</option>
  <option value="2" selected="selected">All Admin Offers</option>
  <option value="3">CPC/CPM</option>
  <option value="4">ect...</option>
</select> 

我自己无法正确完成

有人可以帮忙吗?

4

2 回答 2

2
    <div id="offers-menu">      
   <?php
   function custom_get_categories_options($rootid = 0,$selected = false,$ident = 0) {
    $db = Bux::getDbInstance();
    $q = $db->query("SELECT * FROM ".clix_offers::$table['categories']." WHERE parent_id = ".(int)$rootid);
    $str = '';
    $ident++;
    while($row = $db->fetchAll($q)) {

      $str .= '<option value="'.$row['id'].'" '.'onClick="window.location = \'?cat_id='.$row['id'].'\'"';
      (($_GET['cat_id'] == $row['id']) ? $str .= 'selected="selected">' : $str .= '>');
      $str .= $row['name'].'</option>';
    }

    if($str != "") return $ident>0?"<ol>{$str}</ol>":"{$str}";
   }
   ?>       

        <select>
            <option onClick="window.location = '?cat_id=all'">All Admin Offers</option>
                <?=custom_get_categories_options();?>
        </select>

    </div>
于 2012-07-22T11:30:25.157 回答
0

Perhaps you could have a look at HTML <optgroup /> tag.

Unfortunately it does not allow nested groups or multi-level.

于 2012-07-22T11:26:27.313 回答