小眼清清
2018-09-06 17:29
function conn(){ try{ $pdo = new PDO("mysql:host=127.0.0.1;dbname=test",'root','root'); $pdo->exec("set names utf8"); return $pdo; }catch(PDOException $ex){ $ex->getMessage(); } } function getlist($pid = 0,$result = [],$num = 0){ $num++; $pdo = conn(); $sql = "select * from cate where pid = " . $pid; $res = $pdo->prepare($sql); $res->execute(); while($data = $res->fetch(PDO::FETCH_ASSOC)){ static $result; $data['catename'] = str_repeat("|—",$num) . $data['catename']; $result[] = $data; getlist($data['id'],$result,$num); } return $result; } $res = getlist(); echo "<pre/>"; print_r($res);
写的不错
PHP无限级分类技术
30076 学习 · 83 问题
相似问题
回答 1
回答 1