我目前有一个在mySQL Workbench 5.2中工作的mySQL查询,但不幸的是,当我将其翻译到我的php文件中时,CONCAT函数只能获取FirstName,而无法获取LastName。如果我不使用单引号来构建名字之间的空格,则可以检索到全名,但是当我添加用于间隔的代码时,它只会检索到名字的第一部分。
例如,如果我不在名称之间添加间距并使用以下修改后的代码调用EmployeeName,则可以正常工作:
SELECT * , concat(FirstName,LastName) as 'EmployeeName'
但是输出的结果将会是BruceWayne
下面的代码是使用CONCAT函数调用EmployeeName时无法检索到LastName的地方。
$sql = "
SELECT * , concat(FirstName," . "' '" . ",LastName) as 'EmployeeName'
FROM tblEquipment e
INNER JOIN tblEmployee em on em.employee_id = a.employee_id
INNER JOIN tblStatus s on s.Status_id = e.equipment_id
WHERE e.name = " . "'" . $q . "'" . ";
";
while($row = mysql_fetch_array($result))
{
echo "
<td>
Equipment ID:
</td>
<td>
<input type='text' size='25' disabled value = " . $row['Equipment_ID'] . ">
</td>
<td style='padding-left:10px;'>
Currently Assigned To:
</td>
<td>
<input type='text' size='25' disabled value = " . $row['EmployeeName'] . ">
</td>
";
}
输出仅为名字“Bruce”。有人有任何建议吗?
FirstName," . "' '" .
-works->FirstName, ' ',
- UnholyRanger