不做什麼解釋了,早寫的了,已經忘的差不多了,使用只要更改相應的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($num>0)
{
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="
";
return $var;
}
function show_child($con,$result,$layer)
{
$numrows=mysql_num_rows($result); //計算有多少個一級項
if($numrows>0)
{
echo "
$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_2>0)
{
echo "
";
echo "
";
}
else
{
}
}
echo "
"; while($row=mysql_fetch_array($result)){
|
".$row["class_name"]." |
";echo "
|
"; echo show($con,$pid); echo " |
";
}
}
mysql_close($con);
?>