从表中选择特定字段?

use*_*073 0 php sql resultset

我使用以下SQL查询:

Select * from table1 as t1, table2 as t2 where t1.id = t2.col
Run Code Online (Sandbox Code Playgroud)

但我的问题是这两个表都有相同名称的字段place.那么如何placetable2我的PHP代码中选择名称中的列?我想使用以下PHP代码

 while($row_records = mysql_fetch_array($result_records))
    {

            <?  echo $row_records['place']; ?>

     }
Run Code Online (Sandbox Code Playgroud)

如何从特定表中获取字段?

CJM*_*CJM 6

永远不要用......

Select * from ...
Run Code Online (Sandbox Code Playgroud)

...在生产环境中 - 始终明确指定要返回的列.

因此,您可以将SQL修改为:

Select t1.Place as T1Place, t2.Place as T2Place
  from table1 as t1, table2 as t2 where t1.id = t2.col
Run Code Online (Sandbox Code Playgroud)

所以在你的PHP中你会有:

 while($row_records = mysql_fetch_array($result_records))
 {

        <?  echo $row_records['T2Place']; ?>

 }
Run Code Online (Sandbox Code Playgroud)