function cat_list( $type = "category", $catid = 0, $selected = 0, $re_type = true, $level = 0, $is_show_all = true )
{
$data = read_static_cache( $type."_pid_releate" );
if ( $data === false )
{
if ( in_array( $type, array( "area", "corp" ) ) )
{
$sql = "SELECT c.".$type."id, c.".$type."name, c.parentid, c.".$type."order, COUNT(s.".$type.( "id) AS has_children FROM `".$db_mymps ).$type.( "` AS c LEFT JOIN `".$db_mymps ).$type."` AS s ON s.parentid=c.".$type."id GROUP BY c.".$type."id ORDER BY c.parentid, c.".$type."order ASC";
}
else
{
$sql = "SELECT c.catid, c.html_dir, c.catname, c.parentid, c.if_view, c.catorder, COUNT(s.catid) AS has_children FROM `".$db_mymps.$type.( "` AS c LEFT JOIN `".$db_mymps ).$type."` AS s ON s.parentid=c.catid GROUP BY c.catid ORDER BY c.parentid, c.catorder ASC";
}
$res = $db->getall( $sql );
if ( $type == "corp" )
{
$sql = NULL;
}
else if ( $type == "area" )
{
$sql = NULL;
}
else
{
$sql = NULL;
}
$newres = array( );
if ( count( $res ) <= 1000 )
{
write_static_cache( $type."_pid_releate", $res );
}
}
else
{
$res = $data;
}
if ( empty( $res ) == true )
{
if ( $re_type )
{
return "";
}
return array( );
}
$options = cat_options( $type, $catid, $res );
$children_level = 99999;
if ( $is_show_all == false )
{
foreach ( $options as $key => $val )
{
if ( $children_level < $val['level'] )
{
unset( $options->$key );
}
else if ( $val['is_show'] == 0 )
{
unset( $options->$key );
if ( $val['level'] < $children_level )
{
$children_level = $val['level'];
}
}
else
{
$children_level = 99999;
}
}
}
if ( 0 < $level )
{
if ( $catid == 0 )
{
$end_level = $level;
}
else
{
$first_item = reset( $options );
$end_level = $first_item['level'] + $level;
}
foreach ( $options as $key => $val )
{
if ( $end_level <= $val['level'] )
{
unset( $options->$key );
}
}
}
if ( in_array( $type, array( "area", "corp" ) ) )
{
do
{
if ( $re_type == true )
{
$select = "";
if ( is_array( $options ) )
{
foreach ( $options as $var )
{
$select .= "<option value=\"".$var[$type."id"]."\" ";
if ( is_array( $selected ) )
{
$select .= in_array( $var[$type."id"], $selected ) ? "selected='ture' style='background-color:#6eb00c; color:white!important;'" : "";
}
else
{
$select .= $selected == $var[$type."id"] ? "selected='ture' style='background-color:#6eb00c; color:white!important;'" : "";
}
$select .= ">";
if ( 0 < $var['level'] )
{
$select .= str_repeat( "&nbsp;", $var['level'] * 4 );
}
$select .= htmlspecialchars( $var[$type."name"], ENT_QUOTES )."</option>";
continue;
}
else 
{
return $select;
}
else
{
if ( is_array( $options ) )
{
foreach ( $options as $key => $value )
{
$options[$key]['url'] = $value[$type."id"];
continue;
}
else
{
return $options;
}
else
{
if ( !( $re_type == true ) )
{
break;
}
else
{
$select = "";
foreach ( $options as $var )
{
$select .= "<option value=\"".$var['catid']."\" ";
if ( is_array( $selected ) )
{
$select .= in_array( $var['catid'], $selected ) ? "selected='ture' style='background-color:#6eb00c; color:white!important;'" : "";
}
else
{
$select .= $selected == $var['catid'] ? "selected='ture' style='background-color:#6eb00c; color:white!important;'" : "";
}
$select .= ">";
if ( 0 < $var['level'] )
{
$select .= str_repeat( "&nbsp;", $var['level'] * 4 );
}
$select .= htmlspecialchars( $var['catname'], ENT_QUOTES )."</option>";
}
}
}
}
}
}
}
}
return $select;
} while ( 0 );
foreach ( $options as $key => $value )
{
$options[$key]['url'] = $value['catid'];
}
return $options;
}

解决方案 »

  1.   

    我运行了你的函数,错误如下:Parse error: syntax error, unexpected T_ELSE in D:\MyPHP\WmxCMS\testfun.php on line 121我看了一下,if有点太多了,{}都没有正确关闭,只能一个一个去确认补齐了
      

  2.   

     $select .= htmlspecialchars( $var[$type."name"], ENT_QUOTES )."</option>";
                                                                                                    continue;
                                                                                    }
                                                                                    else
                                                                                    {
                                                                                                    return $select;
                                                                                    }
                                                                                    else
                                                                                    {这个位置,你看看. 两个else 连在一起了.. 真难找啊