我将如何输出这个表?
我正在尝试输出某些产品的价格,这些产品均来自不同的供应商。产品位于行中,供应商位于列中。这似乎是一件很容易做的事情,但我不知道如何使用 PHP 来做到这一点。
产品存储在产品表中,供应商存储在供应商表中,价格存储在定价表中。有一些共同的 ID 字段将它们全部链接起来。定价表中的示例记录可能是:
product_id = 5, category_id = 2, vendor_id = 8, product_price = $5.50
在我的表中,供应商在各列中的顺序始终相同。但是,如何构建查询和 PHP 才能获得输出?我知道这是一个基本问题,但我对此比较陌生,需要一些帮助。如果您能帮我输出如下所示的表格,请先致谢。
如下:
(
)
pricesmodel_idvendor_idcategory_idprice
排序)
链接
我的
信息
:
表结构
编辑
网站以获取更多
到
(
用于
vendorsvendor_idvendor_namemodelsmodel_idmodel_namemodel_link
product_categoriescategory_idcategory_namecategory_order
<h2>Pet Foods</h2>
<table>
<tr>
<td>Product</td>
<td>Vendor 1</td>
<td>Vendor 2</td>
<td>Vendor 3</td>
</tr>
<tr>
<td>Cat Food</td>
<td>$5</td>
<td>$6</td>
<td>$5.50</td>
</tr>
</table>
I'm trying to output prices for some products, all from different vendors. The products are in the rows and the vendors are in the columns. It seems like an easy enough thing to do but I can't figure out how I'd do this with PHP.
The products are stored in a products table, the vendors are in a vendor table, prices are in a pricing table. There are common ID fields that link them all up. A sample record from the pricing table might be:
product_id = 5, category_id = 2, vendor_id = 8, product_price = $5.50
In my table, the vendors will always be in the same order across the columns. But, how do I structure the query and PHP so I can get that output? I know this is a basic question but I'm relatively new to this and need some help. Thanks in advance if you can help me output a table like the one below.
Edit: My table structure is as follows:
product_categories
category_id
category_name
category_order (used to sort)
vendors
vendor_id
vendor_name
models
model_id
model_name
model_link (link to the website for more info)
prices
model_id
vendor_id
category_id
price
<h2>Pet Foods</h2>
<table>
<tr>
<td>Product</td>
<td>Vendor 1</td>
<td>Vendor 2</td>
<td>Vendor 3</td>
</tr>
<tr>
<td>Cat Food</td>
<td>$5</td>
<td>$6</td>
<td>$5.50</td>
</tr>
</table>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我假设您有相同的供应商,并且没有丢失供应商数据,但我仍然会进行一些检查,看看我是否没有错过任何供应商价格数据。你可以轻松做到这一点。
祝你好运!
I have assumed in this that you have same vendors and no vendor data is missing, but I will still put some check to see if I haven't missed any vendor price data. you can easily do that.
Good luck!