<?php
header ( "content-type:text/html;charset=utf-8" );
$link = mysql_connect ( "localhost", "root", "" );
mysql_select_db ( "test" );
mysql_query ( "set names utf8" );
$res=deeploop2();
foreach ($res as $key=>$val){
echo "<a href='{$val['id']}'>".$val['catename']."</a>".">";
}
/**
* 无限极分类技术
* @param int $pid
* @param array $result
* @param int $space
* @return string
*/
function deeploop($pid = 0, &$result = array(), $space = 0) {
$space = $space + 2;
$query = "select * from deeploop where pid=$pid";
$res = mysql_query ( $query );
while ( $row = mysql_fetch_array ( $res, MYSQL_ASSOC ) ) {
$row ['catename'] = str_repeat ( " ", $space ) . "|————" . $row ['catename'];
$result [] = $row;
deeploop ( $row ['id'], $result, $space );
}
return $result;
}
function deeploop2($id = 11,&$result=array()) {
$query = "select * from deeploop where id=$id";
$res = mysql_query ( $query );
while ( $row = mysql_fetch_assoc ( $res ) ) {
$result[]=$row;
deeploop2($row['pid'],$result);
}
krsort($result);
return $result;
}
mracale
2014-09-26
举报
0/150
提交
取消