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

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