2009-07-16 91 views
0
function build_list($id=0,$collapsed="") //return an array with the categories ordered by position 
{ 

$RootPos = ""; 
$this->c_list = array(); 

if($id != 0){ 
$this_category = $this->fetch($id); 
$positions  = explode(">",$this_category['position']); 
$RootPos  = $positions[0]; 
} 

// lets fetch the root categories 
$sql = "SELECT * 
     FROM ".$this->table_name." 
     WHERE position RLIKE '^([0-9]+>){1,1}$' AND c_group =  '".$this->Group."' 
     ORDER BY c_name"; 
$res = mysql_query($sql) or die(trigger_error("<br><storng><u>MySQL Error:</u></strong><br>".mysql_error()."<br><br><storng><u>Query Used:</u></strong><br>".$sql."<br><br><storng><u>Info:</u></strong><br>",E_USER_ERROR)); 

while($root = mysql_fetch_array($res)){ 
$root["prefix"] = $this->get_prefix($root['position']); 
$this->c_list[$root['id']] = $root; 

    if($RootPos == $root['id'] AND $id != 0 AND $collapsed != ""){ 
    $this->list_by_id($id); 
    continue; 

}else{ 

// lets check if there is sub-categories 
    if($collapsed == "" AND $id==0){ 
    $has_children = $this->has_children($root['position']); 
    if($has_children == TRUE) $this->get_children($root['position'],0); 
}}} 
return $this->c_list; 
} 

//他是代码的作者...... 分类 类作者:莎迪·阿里打印类别和子类别单独

现在我只想返回类别和子类别从上面的代码。

function browse() { 

$categories = new categories; 
$categories_list = $categories->build_list(); 

    foreach($categories_list as $c) 
     { 


      return $c->$id; 

    } 
} 

上述代码不工作....任何人都可以帮助我。

回答

0

这里有两个问题与浏览()函数:

  • return语句是foreach循环中。该语句将为$ categories-list中的一个项目(最多)返回一个值,而不会继续循环到$ categories-list的其余部分。

  • 的$ id变量从未宣布或return $c->$id初始化,也许你想用$c['id']$c->id