0

When the result of a query exists, I want to know the name of the row(s) that have the correct results:

$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)){}

simply talking its if(Data1 == curDate)return Data1; if(Data2 == curDate)return Data2....

Sorry for my bad english.

Paweł Tomkiel
  • 1,974
  • 2
  • 21
  • 39
Vinicius Albino
  • 743
  • 2
  • 8
  • 21
  • Why do you need this information? You _know the table name when you write the query_, so why ask the database for something you already know, or are you confusing "tables" with "rows"? – Bojangles Sep 18 '11 at 01:14
  • I don't understand your question. Aren't you querying a single table in that statement? – Carl F. Sep 18 '11 at 01:16
  • Your table name is Programacao. Also that query limits the result set to either being empty or returning "1". Please clarify what you are trying to do. – gview Sep 18 '11 at 01:16

3 Answers3

3

Well it would be Programacao from your query. But if you needed it dynamically you could try functions like mysql_table_name() or mysql_field_name().

Jason McCreary
  • 71,546
  • 23
  • 135
  • 174
0

A select statement does not go into a table.
It goes into a resultset.
Resultsets do not have names, they just are.

http://en.wikipedia.org/wiki/Result_set

Johan
  • 74,508
  • 24
  • 191
  • 319
0

Perhaps you mean this? (either with UNION or UNION 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'
         " ;
ypercubeᵀᴹ
  • 113,259
  • 19
  • 174
  • 235