连接具有相同名称的列的表时,PHP中出现问题 [英] Problem in PHP when joining tables having columns with the same name

查看:58
本文介绍了连接具有相同名称的列的表时,PHP中出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在MySQL中,我连接了两个表,两个表都有一个名为名称"的列.在PHP中,我正在编写一个脚本,该脚本检索列的值并将其存储在变量中:

In MySQL I have joined two tables which both have a column named 'Name'. In PHP I am writing a script that retrieve the values of the columns and store it in variables:

$row = mysql_fetch_array($result);

$table1name = $row['Name'];   
$table2Name = $row['Name'];

当然,变量将不会给出2列的值,但是它们都将在第二个表的列中给出相同的值.有没有一种方法可以在不更改数据库中列名称的情况下检索两个列的不同值?

Of course the variables will not give the values of the 2 columns, but they will both give the same value from the column of the second table. Is there a way, without changing the name of the columns in the database, to retrieve the distinct values of both columns?

推荐答案

您需要在mysql中使用别名

You need to use alias in mysql

SELECT table1.name AS name1

这篇关于连接具有相同名称的列的表时,PHP中出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆