search for in the  
<mysql_field_seekmysql_field_type>
Last updated: Thu, 19 May 2005

mysql_field_table

(PHP 3, PHP 4, PHP 5)

mysql_field_table -- Get name of the table the specified field is in

Description

string mysql_field_table ( resource result, int field_offset )

Returns the name of the table that the specified field is in.

Parameters

result

The result resource that is being evaluated. This result comes from a call to mysql_query().

field_offset

The numerical field offset. The field_offset starts at 0. If field_offset does not exist, an error of level E_WARNING is also issued.

Return Values

The name of the table on success.

Examples

Example 1. A mysql_field_table() example

<?php
$result
= mysql_query("SELECT name,comment FROM people,comments");
if (!
$result) {
   echo
'Could not run query: ' . mysql_error();
   exit;
}

// Assuming name is in the people table
$table = mysql_field_table($result, 'name');
echo
$table; // people
?>

Notes

Note: For downward compatibility, the following deprecated alias may be used: mysql_fieldtable()



User Contributed Notes
mysql_field_table
doelling_at_publicform_dot_de
12-Nov-2004 09:08
Similarly to the behaviour described by cptnemo this function returns only the name of the first table when you use a JOIN.
For example with the query below the table name would be table1 for all fields:

SELECT table1.*, table2.this_thing, table3.that_thing FROM table1 LEFT JOIN table2 ON table1.tb2_id = table2.id LEFT JOIN table3 ON table1.tb3_id = table3.id

The expected behaviour would be, that the table name for the field this_thing is table2 and table3 for the field that_thing respectively.
cptnemo
14-Aug-2004 09: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_seekmysql_field_type>
 Last updated: Thu, 19 May 2005
Copyright © 2001-2005 The PHP Group
All rights reserved.
This unofficial mirror is operated at: The Server Pages
Last updated: Thu May 19 17:35:34 2005 CDT