开发者

MySQL Query - Result Table Name

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 h开发者_运维问答ow 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


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).


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜