不做什么解释了,早写的了,已经忘的差不多了,使用只要更改相应的sql语句就可以
//js的脚本完成张合
$GLOBALS["ID"] =1;
$layer=1;
$con=mysql_connect("127.0.0.1","root","");
if(!$con)
{
echo "级连菜单库连接出错!";
exit();
}
mysql_select_db("soohuo");
$sql="select * from t_class where parent_id=0";
$result=mysql_query($sql,$con);
$num=mysql_num_rows($result);//计算是否有上级
if($num0)
{
show_child($con,$result,$layer,$ID);
}
function show($con,$pid)
{
$var_td="";
$var_tr="";
$sql="select * from t_class where parent_id=$pid";
$result1=mysql_query($sql,$con);
$j=0;
while($row=mysql_fetch_array($result1))
{
$sql="select * from t_class where parent_id=".$row["class_id"];
$result2=mysql_query($sql,$con);
$num2=mysql_num_rows($result2);
//$var_td="";
if($num2==0)
{
$var_td.="
".$row["class_name"]."
";
$j++;
if($j%5==0)//每行的显示数
$var_td.="";
}
else
{
$var_tr=$var_tr."
".$row["class_name"]."
".show($con,$row["class_id"])."
";
//show_child($con,$result2,$layer);
}
}
$var="".$var_td."".$var_tr."";
return $var;
}
function show_child($con,$result,$layer)
{
$numrows=mysql_num_rows($result); //计算有多少个一级项
if($numrows0)
{
echo "";
while($row=mysql_fetch_array($result))
{
$pid=$row["class_id"];
$sql="select * from t_class where parent_id=$pid";
$result_sub=mysql_query($sql,$con);
$num_2=mysql_num_rows($result_sub);
if($num_20)
{
echo "
".$row["class_name"]."
";
echo "";
echo "
";
echo show($con,$pid);
echo "
";
}
else
{
}
}
echo "";
}
}
mysql_close($con);
?