Mall Column Development

Source: Internet
Author: User

Mall Column page on the left there is a column grading bar, click on a column, the middle will show the current position in the first page under the column, to achieve clarity.

category.php

<?phpdefine (' ACC ', true); require ('./include/init.php '); $cat _id = Isset ($_get[' cat_id '])? $_get[' cat_id ']+0:0;$ Cat = new Catmodel (), $category = $cat->getrow ($cat _id), if (Empty ($category)) {    header (' location:index.php ');    Exit;} Take out the tree-like navigation $cats = $cat->select (); Get all Columns $sort = $cat->subtree ($cats, 0,0);//Remove breadcrumb navigation $nav = $cat->familytree ($cats, $cat _id);//Remove the item under the column $goods = New Goodsmodel (); $goodslist = $goods->catgoods ($cat _id); include (ROOT. ' view/front/lanmu.html ');? >

The method used

catmodel.class.php//Find the Family tree public function Familytree ($arr, $id) {static $tree =array (); foreach ($arr as $v) {if ($v [' ID ']= = $id) {//Determine if you want to find the parent column if ($v [' parent_id ']>0) {$this->familytree ($arr, $v [' parent_id ']);} $tree []= $v;}} return $tree;} Recursively format data, find descendants tree Public function subtree ($arr, $id =0, $lev =0) {static $result =array (), foreach ($arr as $v) {if ($v [' Parent_ Id ']== $id) {$v [' Lev ']= $lev; $result []= $v; $this->subtree ($arr, $v [' id '], $lev + 1)}} return $result;}        goodsModel.class.php/* Remove the item from the specified column//$cat _id = $_get[' cat_id '); $sql = select:        From goods where cat_id = $cat _id;        This is wrong because the $cat_id corresponding column may be a big column, and there is no product under the big column.        The goods are placed under the small column under the Big column.    Therefore, the correct way is to find out all the descendants of $cat_id, and then check all the $cat_id and their descendants of the product under the column.        */Public Function catgoods ($cat _id) {$category = new Catmodel (); $cats = $category->select ();  Remove all columns to $sons = $category->getson ($cats, $cat _id);        Take out the Descendants column of the given column $sub = array ($cat _id); if (!empty ($sons)) {//No descendant columns($sons as $v) {$sub [] = $v [' cat_id '];        }} $in = Implode (', ', $sub); $sql = ' Select Goods_id,goods_name,shop_price,market_price,thumb_img from '. $this->table. ' Where cat_id in ('. $in.        ') Order by Add_time limit 5 ';    return $this->db->getall ($sql); }/* Get more information about items in your shopping params array $items the product array in the shopping cart return product Array Details */Public Function GETCARTG Oods ($items) {foreach ($items as $k + $v) {//cycle the items in the cart, one per cycle, to the data to check the corresponding details $sql = ' Select goods_id, Goods_name,thumb_img,shop_price,market_price from '. $this->table. ' Where goods_id = '.            $k;            $row = $this->db->getrow ($sql);            $items [$k] [' thumb_img '] = $row [' thumb_img '];                $items [$k] [' market_price '] = $row [' Market_price '];           } return $items; }

Show Page lanmu.php part of the program

<div class= "Cate_tree" >            <div class= "Lib_top" > Product categories </div>                <div class= "Lib_mid" >                <ul>                    <?php foreach ($sort as $c) {?>                                        <li class= "cate_level_<?php echo $c [' Lev '];? > "><a href=" category.php?cat_id=<?php echo $c [' id '];? > "><?php echo $c [' cat_name '];? ></a></li>                    <?php}?>                                                                       </ul>                </div>                <div class= "Lib_down" > </div>            </div>

Current position: <a href= "index.php" > Home </a>             <?php foreach ($nav as $c) {?>            <code>></code > <a href= "category.php?cat_id=<?php echo $c [' id '];? > "><?php echo $c [' cat_name '];? ></a>            <?php}?>

Mall Column Development

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.