2011-09-18 172 views
0

當查詢的結果存在,我想知道,有正確的結果行(S)的名稱:表名結果查詢

$query = "SELECT Id FROM Programacao WHERE ID = 1"; 
$curDate = date("Y-m-d H").':00:00'; 
$query = "SELECT Id 
    FROM Programacao 
    WHERE Data1 = '$curDate' 
     OR Data2 = '$curDate' 
     OR Data3 = '$curDate'" 
$result = mysql_query($query); 
while ($row = mysql_fetch_array($result)){} 

簡單地談論它if(Data1 == curDate)return Data1; if(Data2 == curDate)return Data2 ....

對不起,我的英語不好。

+0

爲什麼需要此信息?你在編寫query_時知道表名,爲什麼要問數據庫你已經知道的東西,或者你把「表」與「行」混淆了? – Bojangles

+0

我不明白你的問題。你不是在那個陳述中查詢單個表嗎? –

+0

您的表名是Programacao。此外,該查詢將結果集限制爲空或返回「1」。請說明你正在嘗試做什麼。 – gview

回答

0

也許你的意思是? (UNIONUNION ALL):

$query = " 
    SELECT Id 
     , 'Data1' AS name 
    FROM Programacao 
    WHERE Data1 = '$curDate' 
UNION 
    SELECT Id 
     , 'Data2' 
    FROM Programacao 
    WHERE Data2 = '$curDate' 
UNION 
    SELECT Id 
     , 'Data3' 
    FROM Programacao 
    WHERE Data3 = '$curDate' 
     " ;