suche nach in der

mysql_field_type> <mysql_field_seek
Last updated: Fri, 18 May 2012

view this page in

mysql_field_table

(PHP 4, PHP 5)

mysql_field_table Liefert den Namen der Tabelle, die das genannte Feld enthält

Beschreibung

string mysql_field_table ( resource $result , int $field_offset )

Liefert den Namen der Tabelle, die das genannte Feld enthält.

Parameter-Liste

Ergebnis

Das Ergebnis Ressource, das ausgewertet wird. Dieses Ergebnis kommt von einem Aufruf von mysql_query().

Feldoffset

Der numerische Offset des Feldes. Der Feldoffset beginnt bei 0. Falls Feldoffset nicht existiert, wird eine Warnung der Stufe E_WARNING erzeugt.

Rückgabewerte

Der Name der Tabelle bei Erfolg.

Beispiele

Beispiel #1 Ein mysql_field_table() Beispiel

<?php

$query 
"SELECT account.*, country.* FROM account, country WHERE country.name = 'Portugal' AND account.country_id = country.id";

// Erhalte Resultat von der DB
$result mysql_query($query);

// Listet den Tabellennamen und danach den Spaltennamen auf
for ($i 0$i mysql_num_fields($result); ++$i) {
    
$table mysql_field_table($result$i);
    
$field mysql_field_name($result$i);

    echo  
"$table$field\n";
}

?>

Anmerkungen

Hinweis:

Für die Abwärtskompatibiliät kann der folgende veraltete Alias verwendet werden: mysql_fieldtable()

Siehe auch



add a note add a note User Contributed Notes
mysql_field_table
spam at blondella dot de
03-Oct-2006 01:09
<?php
/*
this function might help in the case described above :-)
*/
function mysql_field_table_resolve_alias($inQuery,$inResult,$inFieldName) {
  
$theNameOrAlias = mysql_field_table($inResult,$inFieldName);
  
//check, if AS syntax is being used
  
if(ereg(" AS ",$inQuery))  {
     
//catch words in query
     
$theWords = explode(" ",ereg_replace(",|\n"," ",$inQuery));
     
//find the words preceding and following AS
     
foreach($theWords as $theIndex => $theWord)  {
         if(
trim($theWord) == "AS"
        
&& isset($theWords[$theIndex-1])
         && isset(
$theWords[$theIndex+1])
         &&
$theWords[$theIndex+1] == $theNameOrAlias
        
) {
           
$theNameOrAlias = $theWords[$theIndex-1];
            break
1;
         }
      }
   }
   return
$theNameOrAlias;
}
?>
me at thomaskeller dot biz
23-Nov-2005 10:15
Beware that if you upgrade to MySQL 5 from any earlier version WITHOUT dumping and reloading your data (just by keeping the binary data in MyISAM table files), you might get weird output on the "table" value for mysql_fetch_field and in this function. Weird means that the table name is randomly set or not.

This behaviour seems to popup only if the SQL query contains a ORDER BY clause. A bug is already reported:

http://bugs.mysql.com/bug.php?id=14915

To prevent the issue, dump and reload all participating tables in your query or do

CREATE TABLE tmp SELECT * FROM table;
DROP TABLE table;
ALTER TABLE tmp RENAME table;

on each one via commandline client.
cptnemo
15-Aug-2004 04:18
When trying to find table names for a (My)SQL query containing 'tablename AS alias', mysql_field_table() only returns the alias as specified in the AS clause, and not the tablename.

mysql_field_type> <mysql_field_seek
Last updated: Fri, 18 May 2012