国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

PHP infinite classification navigation LINK style

Implementation schematic

面包屑.png

Navigation LINK style:

<?php
include('conn.php');
function getCatePath($cid, &$result = array()) {
   $sql = "SELECT * FROM deepcate WHERE id=$cid";
   $rs = mysql_query($sql);
   $row = mysql_fetch_assoc($rs);
   if ($row) {
       $result[] = $row;
       getCatePath($row['pid'], $result);
   }
   krsort($result); //krsort對(duì)數(shù)組按鍵名逆向
   return $result;
}
?>

Code explanation:

Same as drop-down style, create getCatePath function, Execute the sql statement to query the id, and pay the obtained value to $rs. Use mysql_fetch_assoc to obtain the array, and call its own getCatePath to query the pid and its own id.

Return $result and sort the array using the reverse method.

Then continue to beautify and encapsulate.

<?php
include('conn.php');
function getCatePath($cid, &$result = array()) {
    $sql = "SELECT * FROM deepcate WHERE id=$cid";
    $rs = mysql_query($sql);
    $row = mysql_fetch_assoc($rs);
    if ($row) {
        $result[] = $row;
        getCatePath($row['pid'], $result);
    }
    krsort($result); //krsort對(duì)數(shù)組按鍵名逆向
    return $result;
}
function displayCatePath($cid,$url='cate.php?cid=') {
    $res = getCatePath($cid);
    $str = '';
    foreach ($res as $key => $val) {
        $str.= "<a href={$url}{$val['id']}>{$val['catename']}</a>>";
    }
    return $str;
}
echo displayCatePath(10);
?>

In this way, the LINK style of infinite classification is completed.


Difficulties in this chapter

1. The link style starts from the parent node and searches downward for its descendant nodes to form a tree shape. The link style determines the current node. The pid is equal to the id of the previous node.

Continuing Learning
||
<?php include('conn.php'); function getCatePath($cid, &$result = array()) { $sql = "SELECT * FROM deepcate WHERE id=$cid"; $rs = mysql_query($sql); $row = mysql_fetch_assoc($rs); if ($row) { $result[] = $row; getCatePath($row['pid'], $result); } krsort($result); //krsort對(duì)數(shù)組按鍵名逆向 return $result; } function displayCatePath($cid,$url='cate.php?cid=') { $res = getCatePath($cid); $str = ''; foreach ($res as $key => $val) { $str.= "<a href={$url}{$val['id']}>{$val['catename']}</a>>"; } return $str; } echo displayCatePath(10); ?>
submitReset Code