gpt4 book ai didi

php - 使用列中的数字创建列号

转载 作者:行者123 更新时间:2023-11-29 18:19:10 25 4
gpt4 key购买 nike

id | ozID  | ozDa1     | ozDa2     |  ozDa3
-----------------------------------------------
1 | 3,4 | Khar | Lorem | Emre
2 | 1,2 | Imson | Berkay | ade
3 | 2 | abc | Goksel | casc
4 | 5 | teq | Insanlik | fdsc
5 | 1,5,2 | asd | Oyle | asdas
6 | 2,1 | fav | Boyle | dsssa
7 | 3 | qwrewq | Filan | dcsd

我可以写这样的内容:

$partNameWD->ozDa2; // Berkay    

但末尾的数字可以是可变的,如下所示:ozDa4

<小时/>

首先我从ozID表中获取数据,例如:1,2

1,2是什么意思?

它指向列号:ozDa1ozDa2

访问此号码的方式如下:

$ozColNo = explode(",", $partNameWD->ozID);

foreach (ozColNo as $ozColId) {
echo ozColId." - "; // 1 - 2
}
<小时/>

那么我的问题是什么?

如何从包含这些数字的列中获取数据?那么,如何打印第一个和第二个的数据

必须对其进行转换:ozDa1//ImsonozDa2//Berkay

请问可以告诉我方法吗?谢谢

最佳答案

我不能 100% 确定我正确理解了问题,但您可以在 information_schema.columns 中获取“列号”和“列名称”之间的映射。因此,如果给您一个号码,您可以使用以下方式查找名称:

select column_name
from information_schema.columns
where table_name = @table_name and table_schema = @table_schema and
ordinal_position = @op;

您可以使用稍微复杂的方法创建一组列(因为我认为排序很重要)

select group_concat(c.column_name order by cols.ordering) as columns
from (select 1 as colpos, 1 as ordering union all
select 2, 2
) cols join
information_schema.columns c
on c.ordinal_position = cols.colpos
where table_name = @table_name and table_schema = @table_schema;

关于php - 使用列中的数字创建列号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46744370/

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