在php,mysql中的parent_id类别页面上显示产品

anauzrmj  于 2023-01-04  发布在  PHP
关注(0)|答案(2)|浏览(134)

我有一个问题,在获得产品的父类别页

我的数据库表结构

CREATE TABLE `tblcategory` (
  `id` int(11) NOT NULL,
  `CategoryName` varchar(200) DEFAULT NULL,
  `Description` mediumtext DEFAULT NULL,
  `Is_Active` int(1) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

分类. php

$pid=intval($_GET['catid']);
$query=mysqli_query($con,
        "select tblposts.id as pid,tblposts.PostTitle as posttitle,
                tblposts.PostImage,tblcategory.CategoryName as category,
                tblsubcategory.Subcategory as subcategory,
                tblposts.PostDetails as postdetails,tblposts.PostingDate as postingdate,
                tblposts.PostUrl as url 
        from tblposts 
            left join tblcategory on tblcategory.id=tblposts.CategoryId 
            left join  tblsubcategory on  tblsubcategory.SubCategoryId=tblposts.SubCategoryId 
        where tblposts.CategoryId='".$_SESSION['catid']."' 
        and tblposts.Is_Active=1 
        order by tblposts.id desc 
        LIMIT $offset, $no_of_records_per_page");

如何删除subcategory
添加parent_id
需要我多类别
有谁能给点建议吗。先谢了。
使用php代码如何在n级分类后进入产品页面

dbf7pr2w

dbf7pr2w1#

SELECT * FROM products
LEFT JOIN categories
ON products.category = categories.category_id
GROUP BY (SELECT parent_id
          FROM categories
          WHERE parent_id = 1  
          GROUP BY parent_id)
qf9go6mv

qf9go6mv2#

对结构做一些调整,探索邻接列表模型和嵌套集模型,根据自己的需要选择合适的,两种模型各有优缺点,主题不短,选择要看很多点。
以下地址也有类似的主题:Adjacency list vs. nested set model

相关问题