Php 从表中选择特定字段?

Php 从表中选择特定字段?,php,sql,resultset,Php,Sql,Resultset,我正在使用以下SQL查询: Select * from table1 as t1, table2 as t2 where t1.id = t2.col 但我的问题是这两个表都有同名的字段,place。 那么,如何在PHP代码中从table2中选择名为place的列呢? 我想使用以下php代码 while($row_records = mysql_fetch_array($result_records)) { <? echo $row_records[

我正在使用以下SQL查询:

Select * from table1 as t1, table2 as t2 where t1.id = t2.col
但我的问题是这两个表都有同名的字段,
place
。 那么,如何在PHP代码中从
table2
中选择名为
place
的列呢? 我想使用以下php代码

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

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

     }
while($row\u records=mysql\u fetch\u array($result\u records))
{
}

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

为什么不使用表别名和字段名。 比如说,

    Select t1.place as t1_place, t2.place as t2_place 
      from table1 as t1, table2 as t2 where t1.id = t2.col
在PHP代码中,可以使用

while($row_records = mysql_fetch_array($result_records))
    {
    echo $row_records['t1_place']; 
    echo '<br />';
    echo $row_records['t2_place']; 
    }
while($row\u records=mysql\u fetch\u array($result\u records))
{
echo$row_记录['t1_位置];
回声“
”; echo$row_记录['t2_位置]; }
切勿使用

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

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

Select t1.Place as T1Place, t2.Place as T2Place
  from table1 as t1, table2 as t2 where t1.id = t2.col
因此,在PHP中,您可以:

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

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

 }
while($row\u records=mysql\u fetch\u array($result\u records))
{
}

零答案,零投票@OP-如果你没有信心/经验回答别人的问题,那没关系,但至少要有礼貌地投票选出有帮助的回答,并选择你认为最有帮助的答案。目前,你只是在偷窥…@所有乐于助人的人:我很抱歉,因为我以前没有接受任何答案。那是因为我不知道如何接受它,我也不知道有办法。我刚刚发布了一个关于如何接受答案的新问题,我没有接受答案,也没有投票。再次表示歉意和感谢。这可能与动态语言无关;这对COBOL这样的语言非常重要,但建议仍然是合理的。假设表格被修改为添加3个额外字段:图片、电影剪辑和PDF文件。您的查询没有使用任何一个字段值,但是您的代码现在支付了传输3个巨大(多兆字节)字段值的费用,只是为了忽略它们。有趣的是:用户现在抱怨你的应用程序的性能。如果你没有编写懒惰的“SELECT*”,你就不会因为不得不回去修改你的愚蠢的懒惰代码而蒙受耻辱。@Hop-Jonathan解释了一个很好的理由;另一个是清晰。然而,我真的对其他情况持开放态度……感谢所有的回答和评论,我刚刚接受了这些回答和评论,并投了赞成票。