如何使用 Opencart 数据库中的表之间的联接进行 SELECT?

发布于 2024-10-30 00:01:10 字数 467 浏览 1 评论 0原文

我正在使用 Opencart 的 1.4.9.4 数据库。由于我对数据库没有经验,我发现结构很奇怪(硬,疯狂)。例如: 如果我需要显示 product 的型号和名称,我需要连接 2 个表 productproduct_description,类别的方法相同、制造商等 有一个表只有两个字段product_to_category,字段:category_idproduct_id。如果我真的应该使用 JOIN,那么我使用了多少个 JOIN 才能使其正常工作? 但一件非常奇怪的事情是进行查询,我获取产品 ID、名称和型号以及类别名称和制造商名称,我不知道如何实现这一点。这将涉及表格,至少我认为: 产品、产品描述、产品类别、类别描述和制造商。 对不起,乱七八糟,但我现在脑子一片混乱!

I'm playing with Opencart's 1.4.9.4 database. And as I'm not experienced with database I find the structure strange (hard,crazy). For example:
if I need to show the model and the name of a product I need to join 2 tables product and product_description, and the same approach for category, manufacturers etc.
There is a table is only two fields, product_to_category, fields: category_id and product_id. How many JOINs show I use, if I really should use JOINs, to make it work?
But one really odd thing for is to make a query where I get the product ID, NAME and MODEL with CATEGORY NAME and MANUFACTURER NAME, I have no knowledge to achieve that. It would involve the table, at least I think:
product, product_description, product_to_category, category_description and manufacturer.
Sorry for the mess, but my mind is a mess now!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

dawn曙光 2024-11-06 00:01:10

在opencart中,您将product_id值连接在一起以获得完整的数据行(并使用where子句设置描述的正确语言ID,这样

SELECT * FROM product p LEFT JOIN product_description pd ON p.product_id = pd.product_id WHERE pd.language_id = 1 LIMIT 20

将从两个表中获取所有数据并使用20的限制正确连接它们products 和语言 1(默认为英语),当然,在 php 中正确编写时,您将需要动态调用一些数据(例如表前缀和语言 id),这样如果您有多种语言或语言,它就可以工作。带有前缀的数据库表。

$query = "SELECT * FROM `" . DB_PREFIX . "product` p LEFT JOIN `" . DB_PREFIX . "product_description` pd ON p.product_id = pd.product_id WHERE pd.language_id = " . (int)$this->config->get('config_language_id') . " LIMIT 20";

In opencart you join the product_id values together to get the full row of data (and use the where clause to set the correct language ID of the description, so

SELECT * FROM product p LEFT JOIN product_description pd ON p.product_id = pd.product_id WHERE pd.language_id = 1 LIMIT 20

That would grab all the data from both tables and join them correctly using a limit of 20 products and the language 1 (default of english). Of course, when writing it properly in php, you will need to call some data dynamically (such as the table prefix and the language id) so it will work should you have multiple languages or database tables with prefixes. Something like

$query = "SELECT * FROM `" . DB_PREFIX . "product` p LEFT JOIN `" . DB_PREFIX . "product_description` pd ON p.product_id = pd.product_id WHERE pd.language_id = " . (int)$this->config->get('config_language_id') . " LIMIT 20";
放手` 2024-11-06 00:01:10

抱歉,我完全忘记了这一点:
MySQL 从 OpenCarts 数据库中选择重复的行
我已经这么问了。

Sorry people I totally forgot about this:
MySQL SELECT Duplicated rows from OpenCarts DataBase
I had already asked that.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文