繁体   English   中英

单独打印类别和子类别

[英]Printing the Categories and Sub Categories Alone

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;
}

//他是代码的作者...分类类作者:Shadi Ali

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

function browse() {

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

    foreach($categories_list as $c)
        {


            return $c->$id;

    }
}

上面的代码无法正常工作。...谁能帮帮我。

这是Browse()函数的两个问题:

  • return语句位于foreach循环内。 该语句将为$ categories-list中的一项(最多)返回一个值,并且不会继续在$ categories-list的其余部分上循环。

  • $ id变量永远不会声明或初始化为return $c->$id ,也许您是要使用$c['id']$c->id

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM