首頁 >php教程 >PHP源码 >作用循环读取某栏目下的所有子栏目。

作用循环读取某栏目下的所有子栏目。

PHP中文网
PHP中文网原創
2016-05-25 17:00:081107瀏覽

php代码:

<?php
//网站导航栏目id
class navigation
{
	var $class;
	var $classstr = "";
	
	function __construct($id)
	{
		$this->class = $id;
	}
	
	function ishave($id)
	{
		global $myobj,$language;
		$sql = "select * from cy_{$language}_sitecategory where did = ".$id;
		$result = $myobj->getRowsRst($sql);
		return $result;
	}
	
	function subclass($id)
	{
		global $myobj,$language;
		$sql = "select * from cy_{$language}_sitecategory where did = ".$id;
		$rs = $myobj->query($sql);
		while($rt = $myobj->getarray($rs))
		{
			$classstr .= $rt[&#39;id&#39;].&#39;, &#39;;
		}
		return $classstr;
	}	
	
	function classname()
	{
		global $myobj,$language;
		$tmpstr = "";
		$sql = "select * from cy_{$language}_sitecategory where did = ".$this->class;
		$rs = $myobj->query($sql);
		while($rt = $myobj->getarray($rs))
		{
			if($this->ishave($rt[&#39;id&#39;]))
			{
				$tmpstr = $this->subclass($rt[&#39;id&#39;]);
			}
			$classstr .= $rt[&#39;id&#39;].&#39;, &#39;;
		}
		return empty($tmpstr)?$classstr:$classstr.$tmpstr;
	}
	
}


?>
陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn