[英]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;
}
// He is the Author of the code... Categories Class Author: Shadi Ali //他是代码的作者...分类类作者:Shadi Ali
Now I want to just return the Categories and Sub Categories from the above code. 现在,我只想从上面的代码返回类别和子类别。
function browse() {
$categories = new categories;
$categories_list = $categories->build_list();
foreach($categories_list as $c)
{
return $c->$id;
}
}
The above code is not working.... can anyone help me out. 上面的代码无法正常工作。...谁能帮帮我。
Here are two problems with the browse() function: 这是Browse()函数的两个问题:
The return statement is inside the foreach loop. return语句位于foreach循环内。 The statement will return one value for one of the items in the $categories-list (at most), and not continue to loop over the rest of the $categories-list. 该语句将为$ categories-list中的一项(最多)返回一个值,并且不会继续在$ categories-list的其余部分上循环。
The $id variable is never declared or initialised in return $c->$id
, perhaps you meant to use $c['id']
or $c->id
$ id变量永远不会声明或初始化为return $c->$id
,也许您是要使用$c['id']
或$c->id
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.