Home > Backend Development > PHP Tutorial > PHP realizes infinite classification. PHP Infinitus classification display. PHP Infinitus classification drop-down box. PHP Infinitus classification letter.

PHP realizes infinite classification. PHP Infinitus classification display. PHP Infinitus classification drop-down box. PHP Infinitus classification letter.

WBOY
Release: 2016-07-29 08:49:58
Original
1509 people have browsed it

If you write a system by yourself, you will often use column management

If there are many levels of column classification, you need to implement infinite classification. The code is as follows

1. Usage in the drop-down menu

/*  无限级分类
 *
 *	逻辑递推获取类型
 *	hid 上级栏目id
 *	step 下级栏目前缀
 *	tid seleted选项id
 */
 
function LogicGetTypeList($datatable='lanmu_class',$hid=0,$step='',$tid=-1)
{
	
	static $TypeList='';
	$query = "SELECT * FROM `$datatable` WHERE heid=$hid ORDER BY px ASC";
	$arrs=mysql_query($query);
	while($row=@mysql_fetch_assoc($arrs)){
		echo $step;
		$TypeList .= ("<option value=&#39;".$row[&#39;id&#39;]."&#39; ");
		$TypeList .= ($tid == $row[&#39;id&#39;]? &#39;selected&#39; : &#39;&#39;);
		$TypeList .= (" >".$step.$row['class']."</option>\r\n");  //分类名称
		LogicGetTypeList($datatable,$row['id'],$step.'--',$tid);
	}
	return $TypeList;
}
Copy after login
2. Column management

The code is roughly as follows and needs to be modified according to the specific situation

<?php
treeList("",0);
function treeList($tag,$classid){
$result=mysql_query("select * from lanmu_class where heid=&#39;".$classid."&#39; order by px asc");
while($row=mysql_fetch_array($result)){

/*栏目功能*/
$sqlG=@mysql_fetch_assoc(mysql_query("select * from ht_gn where id=&#39;".$row[&#39;gongn&#39;]."&#39;"));
?>
<tr class="blue"   
  <td width="5" align="center" class=""><input type="checkbox" name="dell[]" value="<?php echo $row[&#39;id&#39;]?>"></td>
<td class=""><?php echo $tag.$row[&#39;class&#39;];?></td>
<td class=""><?php echo $sqlG[&#39;gn_title&#39;];?></td>
<td align="center" class=""><?php echo $row[&#39;template&#39;];?> </td>
<td align="center" class=""><input type="text" value="<?php echo $row["px"]?>" size="3"  echo $row['id'];?>,this.value)" /> </td>    
<td class="">
【<a href="lanmu_add.php?id=<?php echo $row[&#39;id&#39;];?>">编辑</a>】  【<a href="#"  echo $row[&#39;id&#39;]?>'}">删除</a>】
  【<a href="../car/car_pic.php?s_id=<?php echo $row[&#39;id&#39;];?>">图片集</a>】
</td> 
</tr>
<?php treeList($tag."─┴─",$row[&#39;id&#39;]);?>
<?php
	}
}
 ?>
Copy after login

The above introduces the implementation of unlimited classification in PHP, including the content of PHP and unlimited levels. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
php
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template