我有一个 SQL 查询,其中有别名。问题是,当我尝试获取列的值时,它没有显示正确的值:
$sql = "SELECT p.ID, p.ProfileID, p.ModuleID, p.View, p.Add, p.Edit, p.Delete, m.Name, m.ID FROM permission AS p, module AS m WHERE p.ModuleID = m.ID ORDER BY p.ProfileID ASC, m.Name ASC";
$result = array();
$i = 0;
foreach ($this->dbconnect->query($sql) as $row)
{
$result[$i] = array(
'ID' => $row['p.ID'],
'ProfileID' => $row['p.ProfileID'],
'ModuleID' => $row['p.ModuleID'],
'View' => $row['p.View'],
'Add' => $row['p.Add'],
'Edit' => $row['p.Edit'],
'Delete' => $row['p.Delete']);
$i += 1;
}
在数据库中实际为 10 时,运行显示没有任何价值。
如果我将上面的代码更改为以下内容:
$sql = "SELECT p.ID, p.ProfileID, p.ModuleID, p.View, p.Add, p.Edit, p.Delete, m.Name, m.ID FROM permission AS p, module AS m WHERE p.ModuleID = m.ID ORDER BY p.ProfileID ASC, m.Name ASC";
$result = array();
$i = 0;
foreach ($this->dbconnect->query($sql) as $row)
{
$result[$i] = array(
'ID' => $row['ID'],
'ProfileID' => $row['ProfileID'],
'ModuleID' => $row['ModuleID'],
'View' => $row['View'],
'Add' => $row['Add'],
'Edit' => $row['Edit'],
'Delete' => $row['Delete']);
$i += 1;
}
奇迹般地,running 显示了 的值m.ID
而不是p.ID
。奇怪的是为什么第一个例子不正确。我在这里错过了什么吗?