Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何获取mysql行中包含字符串的列名_Php_Mysql - Fatal编程技术网

Php 如何获取mysql行中包含字符串的列名

Php 如何获取mysql行中包含字符串的列名,php,mysql,Php,Mysql,我使用SELECT语句选择了表中的特定行。在此行中,我想查找包含特定字符串的列 Col1 | Col2 | Col3 | Col4 | Col5 A | B | D | E | G 我想知道哪个列包含字符串E。谢谢。您可以执行以下操作: select (case when col1 = 'E' then 'col1' when col2 = 'E' then 'col2' when col3 = 'E' then

我使用SELECT语句选择了表中的特定行。在此行中,我想查找包含特定字符串的列

Col1 | Col2 | Col3 | Col4 | Col5
A    |  B   |   D  |   E  |   G

我想知道哪个列包含字符串E。谢谢。

您可以执行以下操作:

select (case when col1 = 'E' then 'col1'
             when col2 = 'E' then 'col2'
             when col3 = 'E' then 'col3'
             when col4 = 'E' then 'col4'
             when col5 = 'E' then 'col5'
        end)
如果您只需要索引:

select field('E', col1, col2, col3, col4, col5)

…我想尝试选择案例选项。如何将此查询应用于行。我想将列的名称存储在一个变量中以供以后使用,例如$colname='col2';。请提供代码片段。我正在使用php和mysql。谢谢