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

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

PHP中文网
PHP中文网Original
2016-05-25 17:00:081148browse

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


?>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn