我有一个查询连接两个共享字段名称的表。在使用 fetch_array 将结果转换为数组后,我想获取一个的字段名称,而不是另一个。
我觉得我已经用一个简单的别名完成了很多次,但这次它不起作用。谁能帮我找出错误。非常感谢。
代码是:
$sql = "SELECT i.*,ic.* FROM `items` i
LEFT JOIN `itemcat` ic ON i.id= ic.itemid
WHERE (shortdescript LIKE '%%' OR longdescript LIKE '%%')
AND ic.catid='23' limit 0,20 ";
$res = mysql_query($sql) or die(mysql_error()); //query executes no problem
while($row = mysql_fetch_array($res)) {
$id = $row['i.id'];//I do not understand why this is not getting anything.
$id2 = $row['id'];//returns id but from wrong table.
echo $id; //returns blank.
echo $id2; //returns id of itemcat table when I want id of items table.
}