gpt4 book ai didi

php - 将列值显示为表标题而不是其原始标题

转载 作者:行者123 更新时间:2023-11-29 14:31:55 24 4
gpt4 key购买 nike

我在 mySQL 中有一个数据库,假设为“Storage”,其中有一个名为“Storage_Det”的表。以下是“Storage_Det”的内容:

valueid | formid |  submissionid |  fieldname  |  fieldvalue
--------+--------+---------------+-------------+-------------
1 | 1 | 1 | name | Alex
2 | 1 | 1 | position | Manager
3 | 1 | 1 | room | 3-10
4 | 1 | 2 | name | Ben
5 | 1 | 2 | position | Accountant
6 | 1 | 2 | room | 2-05
7 | 1 | 3 | name | Denny
8 | 1 | 3 | position | Marketing
9 | 1 | 3 | room | 1-03

我用php显示没有问题。我的问题是:我想为我的新表格 View 显示“名称”、“位置”和“房间”,以便它显示如下:

submissionid | name   | position   | room |
-------------+--------+------------+------+
1 | Alex | Manager | 3-10 |
2 | Ben | Accountant | 2-05 |
3 | Denny | Marketing | 1-03 |

由于我是这里的新手,所以我需要你的帮助。请告诉我。谢谢。

好吧,我想我必须先添加一些细节以使我的问题足够清楚。

“2 号表”不是真实的表。它是根据 1 号表中存储的数据生成的。正如您在“1 号表”数据中看到的,“名称”、“位置”和“房间”将是“2 号表”中的“表头”。我希望这已经足够清楚了。

最佳答案

现在我更好地理解你的问题了,这是一种方法:

CREATE TEMPORARY TABLE  `table2` (
`submissionid` INT NOT NULL ,
`name` VARCHAR( 50 ) NOT NULL ,
`position` VARCHAR( 50 ) NULL ,
`room` VARCHAR( 50 ) NULL
) ENGINE = MYISAM ;

ALTER TABLE `table2`
ADD UNIQUE (
`submissionid` ,
`name` ,
`position` ,
`room`
);

insert table2 (submissionid, name) select submissionid, fieldvalue from table1 where fieldname='name';
update table2 set position = (select fieldvalue from table1 where fieldname='position' and table1.submissionid = table2.submissionid);
update table2 set room = (select fieldvalue from table1 where fieldname='room' and table1.submissionid = table2.submissionid);


select * from table2;

关于php - 将列值显示为表标题而不是其原始标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9854180/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com