views:

49

answers:

3

When I query a mysql database in PHP, I can not figure out how to specify the table of the field in the result set.

For example, I would like to do the following:

$row = mysql_fetch_assoc($result);

$row["table.FIELD"];

But, can not figure out how. Surely, it is able to happen somehow.

EDIT: I have checked documentation, and have found nothing. I am not sure if I was understood at first... I know how to get the value of a field in a row from a result set. But, I would like to be able to get the value of a field in a row by specifying the name of the table in front of that field.

$row["FIELD"]; vs $row["table.FIELD"];

From the above line, I would like to do the latter.

Thanks,

Steve

+1  A: 

It's most likely in $row['FIELD'], depending on how you structured your SQL statement.

Try print_r( $row ) to see everything that's in the array.

ksteinhoff
I already know how to do this. See edit above.
stjowa
A: 

The documentation explains how to do what you want, check the examples.

Alix Axel
Why the downvote?
Alix Axel
+1  A: 

You get it as $row[field_name],
And if you have two fields with same name but from different tables, You must add at least to one of them table.field AS somthing_else

SELECT t1.id,t2.id AS 't2_id' ....
...
...
var_dump($row);

will give $row['id'],$row['t2_id']

While if you don't use the AS you will get only $row['id'] (one value was lost).

Itay Moav