2009-07-16 138 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