亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

PHP ?? ?? ??? ??? ???? ?? ??? ?????. (1)

?? ??? ?????? ???? ???? ???

<?php
$link = mysqli_connect('localhost','username','password','test');
mysqli_set_charset($link, "utf8");
if (!$link) {
  die("連接失敗:".mysqli_connect_error());
}
?>

? ??? ???? ??? 3?? ??? ?????.

sort id type int.

???? ?? ?? varchar ??.

???? pid int ??.

??? ??? ???:

111.png

????:

??? ?? ?? get_str? ????, ?? ??? pid = 0?? ????, SQL ?? ???? ?? ???? ????, ??? ?? ???? $? ?????. ?? ,

while ??? ???? ?? ???? ????, ???? ???? ?? ??? ???, ??? ?? ?? get_str? ????, ?? ???? ID? ??? ?? ??

? ??? ?? ???? ?????. ?? ??.

<?php
function get_str($id = 0) {
  global $str;
  global $link;    //global 關(guān)鍵詞用于訪問(wèn)函數(shù)內(nèi)的全局變量。
  $sql = "select id,title from class where pid= $id";
  $result = mysqli_query($link,$sql);//查詢pid的子類的分類
  if($result){//如果有子類
    $str .= '<ul>';
    while ($row = mysqli_fetch_array($result)) { //循環(huán)記錄集
      $str .= "<li>" . $row['id'] . "--" . $row['title'] . "</li>"; //構(gòu)建字符串
      get_str($row['id']); //調(diào)用get_str(),將記錄集中的id參數(shù)傳入函數(shù)中,繼續(xù)查詢下級(jí)
    }
    $str .= '</ul>';
  }
  return $str;
}
echo get_str(0);
?>

??? ??? ?????.

112.png

???? ??
||
<?php header("content-type:text/html;charset=utf8"); $link = mysqli_connect('localhost','username','password','test'); mysqli_set_charset($link, "utf8"); if (!$link) { die("連接失敗:".mysqli_connect_error()); } //遞歸-返回字符串格式的函數(shù) function get_str($id = 0) { global $str; global $link; //global 關(guān)鍵詞用于訪問(wèn)函數(shù)內(nèi)的全局變量。 $sql = "select id,title from class where pid= $id"; $result = mysqli_query($link,$sql);//查詢pid的子類的分類 if($result){//如果有子類 $str .= '<ul>'; while ($row = mysqli_fetch_array($result)) { //循環(huán)記錄集 $str .= "<li>" . $row['id'] . "--" . $row['title'] . "</li>"; //構(gòu)建字符串 get_str($row['id']); //調(diào)用get_str(),將記錄集中的id參數(shù)傳入函數(shù)中,繼續(xù)查詢下級(jí) } $str .= '</ul>'; } return $str; } echo get_str(0); ?>