gpt4 book ai didi

mysql - Codeigniter事件记录返回指定行的列名

转载 作者:行者123 更新时间:2023-11-29 17:18:51 24 4
gpt4 key购买 nike

是否可以返回表中一行的列名?如果是这样,我该怎么办?

我有一个具有这种结构的表

----------------------------------------------------------------------------
| idx | line1 | line2 | line3 | line1_action | line2_action | line3_action |
----------------------------------------------------------------------------
| 1 | 3 | 2 | 1 | PENDING | PENDING | APPROVED |
----------------------------------------------------------------------------

例如,我有一个 idx = 1 和我的 line = 2,我需要检查我是否位于 的第 1、2 或 3 行>idx = 1,如何返回我所在的列名?

回答了我自己的问题

$requestIdx = $this->session->userdata('request_id');
$staffDepth = 2;
$requestInfo = $this->staffrequisition_model->selectItem(array('idx'=>$requestIdx));
foreach($requestInfo as $key=>$value){
if(preg_match('/line\d/',$key) && $value == $staffDepth) { $lineName = $key; }
}

最佳答案

您不能直接返回列名称。

为此,您必须像下面这样准备查询

SELECT idx, IF(line1 = 2, 'line1', if(line2 = 2, 'line2', line3 = 3, 'line3', '')) AS line, line2, line3 FROM table_name WHERE (line1 = 2 OR line2 = 2 OR line3 = 2) AND idx = 1

关于mysql - Codeigniter事件记录返回指定行的列名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51375254/

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