我运行一个SELECT查询,它已A.ID和c.id像这样:MySQL的SELECT瓦特/,两条AS ID字段名称中使用PHP而mysql_fetch_array(),以确定他们唯一
$sql = "
(SELECT
a.id,
a.Title,
a.Category,
c.id,
c.cateName FROM ads_list
AS a LEFT JOIN ads_cate
AS c ON c.id=a.Category WHERE a.Category = $CatID)"; // $CatID is defined earlier in the script but is not pertinent to this problem.
$result = mysql_query($sql) or die(mysql_error());
while ($row = mysql_fetch_assoc($result)) { echo $row['id'] // equals c.id }
但$行['id']是查询中调用的最后一个id,并且计算为c.id.我需要在while循环中获取a.id。
我的问题是我如何在我的while()循环中唯一获取a.id和c.id的值?
这是一个很好的例子,说明为什么在每个表中将主键'id'命名不好。 –
比尔,谢谢你的提示。 – OldWest
我都叫做id,使用别名有多难(不是很好) – 2011-08-04 22:14:28