我如何为制作的产品目录创建目录? [英] How do i create a directory for a product catalogue im making?

查看:50
本文介绍了我如何为制作的产品目录创建目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个产品目录,该目录将通过数据库查询进行浏览,结果显示在div中,而无需通过ajax进行页面刷新.

I am creating a product catalogue which will be browsed through database queries with the results displayed in a div, without page refresh-via ajax.

类别示例为:

首页健康娱乐

每个类别也有子类别,即:

There are also subcategories for each category, i.e:

HOME:花园家具水暖等等.

HOME: Garden Furniture Plumbing Etc.

我想制作一个目录的小东西,以准确显示它们的位置,例如:

I want to make a little directory thing that shows exactly where they are, something like:

首页>>>园林>>>草坪护理

Home >>> Garden >>> Lawn care

将每个链接作为可点击的链接,以将该人带回该特定查询级别.

With each of those as a clickable link to take the person back to that specific query level.

我的代码是1个.php文件,涉及一个查询和用于输出查询的代码.如果单击输出,则会触发一个ajax脚本,该脚本指向并重新运行相同的查询/输出,但结果不同.

My code is 1 .php document, involving a query and code to output the query. If output is clicked on, it triggers an ajax script which points back to and reruns the same query/output, but with different results.

这就是说,我不知道如何创建一种存储和显示目录路径的方法.我在上面提到过.

This being said, i dont know how i would create a way to store and display the directory path. That i mentioned above.

我正在考虑采取某种方式,使所单击的类别通过URL传递,以便php在重新加载时具有该值.然后,我将该变量转换为可点击的目录链接.但是问题是我不确定如何对多层进行此操作.

I was thinking of some way that takes the category that was clicked on and passes it through the url so that the php has the value when it reloads. And then i work that variable into a clickable directory link. But the problem is I'm not sure how to do that for multiple layers.

即如果有人单击花园",我可以将花园变量传递并在导航中使用它,但是如果有人单击草坪护理",我将不确定如何保留花园"变量,因为我带来了该变量通过该网址现在将显示为草坪护理".

i.e. If someone just clicked on "garden" i could pass the garden variable through and use that in the nav, but then if someone clicked on "lawn care" i wouldnt be sure how to keep the "garden" variable because the variable i brought over via the url would now read "lawn care."

我觉得这与在数组中动态添加和存储累积值有关,但是我真的没有主意...

I feel like it has something to do with dynamically adding and storing the cumulative values in an array, but I'm really out of ideas...

推荐答案

根据您的描述,听起来您想实现面包屑/类别而不是目录.

From what you've described, it sounds like you want to implement bread crumbs/categories rather than directories.

在这种情况下,您基本上需要在数据库中创建一个Categories表,如下所示:

If this is the case, you'd basically need to create a Categories table in your database like so:

Categories
id | parent_id | name
1  | 0         | Home
2  | 1         | Garden
3  | 1         | Furniture
4  | 1         | Plumbing
5  | 2         | Lawn Care

这等同于如下层次结构:

This would equate to a hierarchy like the following:

  • 首页
    • 花园
      • 草坪护理

      例如,如果要在首页>花园>草坪护理中进行产品展示,则需要将该产品链接到类别5(草坪护理).然后,我需要开发一个函数来做一会儿while循环,从那里找出父结构.它需要循环直到找不到父对象为止(或者直到parent_id = 0为止).换句话说,它将:

      So if I want to have a product show, for instance, in Home > Garden > Lawn Care, I'll need to link the product to Category #5 (Lawn Care). Then I need to develop a function to do a little while loop that figures out the parent structure from there. It will need to loop until it doesn't find a parent (or until parent_id = 0). In other words, it would go:

      I'm in Lawn Care. Does Lawn Care have a parent?
      Yes -> Garden. Does Garden have a parent?
      Yes -> Home. Does Home have a parent?
      No -> End.
      

      有很多方法可以实现这一点,这就是为什么我省略细节的原因.

      There are a number of ways to implement this, which is why I left specifics out.

      或者,您可以只在保存产品或类别时执行此计算,这样它可以一次而不是每次都映射层次结构(节省计算),但这将是一种非常简单的解决方案,可以用于大量的产品.

      Alternatively, you could just do this calculation on save of the product or category so it can map out the hierarchy the one time instead of every time (saving on calculations), but this would be a very simple solution that could work for a large number of products.

      这样做的好处是,您还可以根据您所在的类别来实施产品列表,而从另一个角度来看,您可以按类别创建产品计数.

      The benefit to doing it this way is that you can also implement product lists based on the category you're in, and from another perspective, you can create product counts per category.

      这篇关于我如何为制作的产品目录创建目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆