當前我有一個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