当前我有一个cop_config表。我想要的是使用where条件获取一些(不是全部)列名。现在,我只能用下面的代码来获取所有的列名..如何从表中使用where条件获得列名称
$cop_value = "SELECT COLUMN_NAME
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = 'cop_config' and is_nullable = 'NO'";
$cop_result = $conn->query($cop_value);
while($cop_row = $cop_result->fetch_assoc()){
$cop_row = implode(',', $cop_row);
echo $cop_row;
}
currenlty我的输出是:
iddevice_keyfirst_pulse1first_pulse2first_pulse3first_pulse4first_pulse5first_pulse6first_pulse7first_pulse8second_pulse1second_pulse2second_pulse3second_pulse4second_pulse5second_pulse6second_pulse7second_pulse8
从表我想要的是根据device_key(在cop_config表中)只有那些有1个值的列名。我知道我的问题解释不太好,请看表格图片,以便更好地理解您的担忧。
像device_key YMR200,我只是想获得列名 - first_pulse1 & second_pulse2
与之相似的device_key VTA600我想获得列名 - first_pulse3 & second_pulse4。
------------------------------☺☻♀♥♣♦♣W ------ -------- ------------------------ 经过长时间的搜索和谷歌目前我使用
$cop_value = "SELECT 'first_pulse1' from cop_config where first_pulse1 = 1 and device_key = 'VTA600' union
select 'first_pulse2' from cop_config where first_pulse2 = 1 and device_key = 'VTA600' union
select 'second_pulse1' from cop_config where second_pulse1 = 1 and device_key = 'VTA600' union
select 'second_pulse2' from cop_config where second_pulse2 = 1 and device_key = 'VTA600'";
$cop_result = $conn->query($cop_value);
while($cop_row = $cop_result->fetch_assoc()){
echo $cop_row;
}
我knwo我在这里作出错误的错误同时获取值...但我不知道如何从查询中获取值。 PLZ帮助 感谢..
你搜索的PL/SQL基础的解决方案的输出?我能想到的是使用游标遍历行并获取其他列中每个device_key的状态。它应该工作,如果你有固定数量的列。 – Arun
tnx您的回应。我会谷歌的PL/SQL,并让你知道如果这个工作 – metalhead101