PHP 将库存合并到表中

发布于 2024-10-22 01:03:58 字数 1685 浏览 6 评论 0原文

希望这是一个快速且容易回答的问题。

我有一个包含以下字段的 MySQL 数据库: shoe_sizewaist_size

shoe_size 条目的范围为 3 到 21(按一半递增 - 3、3.5、4、4.5 等)。

waist_size 条目也是如此。

我的问题是这样的:

使用 PHP,我怎样才能最好地将其合并到一个计算尺寸总数的表格中,以便它本质上可以用作订单表格

例如,MySQL 表如下所示:

  ---------------------------------------------- 
  |     Name    |   shoe_size   |  waist_size  |
  ----------------------------------------------
  |      John   |      9.5      |      33      |
  ----------------------------------------------
  |     Steve   |       9       |      32      |
  ----------------------------------------------
  |     Tom     |      9.5      |      33      |
  ----------------------------------------------
  |    Sally    |       7       |       8      |
  ----------------------------------------------
  |    Jane     |       7       |       8      |
  ----------------------------------------------

输出 HTML(表?)将如下所示:

                ORDER FORM
  ------------------------------------------
  | Shoe Size     |   7   |   9   |   9.5  |
  ------------------------------------------
  | Total Pairs   |   2   |   1   |   2    |  <----- This is calculated from above
  ------------------------------------------

  ------------------------------------------
  | Waist Size    |   8   |   32   |   33  |
  ------------------------------------------
  | Total Pairs   |   2   |   1   |   2    |  <----- This is calculated from above
  ------------------------------------------

我什至不确定“订单表格”表的格式是否是执行此操作的最佳方式。任何朝着正确方向的推动将不胜感激。

Hopefully this is a quick and easy question to answer.

I have a MySQL Database with the following fields:
shoe_size and waist_size

The shoe_size entries range anywhere from 3 to 21 (incrementing by halves-- 3, 3.5, 4, 4.5, etc).

The same is true for the waist_size entries.

My question is this:

Using PHP, how can I best consolidate this into a table that counts the total number of sizes, so that it could essentially be used as an Order Form?

For example, the MySQL table looks like this:

  ---------------------------------------------- 
  |     Name    |   shoe_size   |  waist_size  |
  ----------------------------------------------
  |      John   |      9.5      |      33      |
  ----------------------------------------------
  |     Steve   |       9       |      32      |
  ----------------------------------------------
  |     Tom     |      9.5      |      33      |
  ----------------------------------------------
  |    Sally    |       7       |       8      |
  ----------------------------------------------
  |    Jane     |       7       |       8      |
  ----------------------------------------------

And the output HTML (table?) would look something like this:

                ORDER FORM
  ------------------------------------------
  | Shoe Size     |   7   |   9   |   9.5  |
  ------------------------------------------
  | Total Pairs   |   2   |   1   |   2    |  <----- This is calculated from above
  ------------------------------------------

  ------------------------------------------
  | Waist Size    |   8   |   32   |   33  |
  ------------------------------------------
  | Total Pairs   |   2   |   1   |   2    |  <----- This is calculated from above
  ------------------------------------------

I'm not even sure if my format for the "Order Form" table is the best way to go on this. Any nudge in the right direction would be greatly appreciated.

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

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

发布评论

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

评论(2

朦胧时间 2024-10-29 01:03:58

MySQL 可能足以完成此任务,尝试类似的方法

SELECT shoe_size, COUNT(id) as count FROM table GROUP BY shoe_size ORDER BY shoe_size asc

MySQL might be enough for this task, try something like

SELECT shoe_size, COUNT(id) as count FROM table GROUP BY shoe_size ORDER BY shoe_size asc
凑诗 2024-10-29 01:03:58

我认为您正在寻找的是 GROUP BY。
(http://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html)

例如:

SELECT `Shoe Size`, COUNT(*) FROM table_name GROUP BY `Shoe Size`

I think what you are looking for is GROUP BY.
(http://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html)

e.g:

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