我有一张表,我正在绘制有关几个字段的信息。特别需要连接的两个字段是Firstname和Surname,但我不能在实际表中添加另一列。
我可以编辑我的PHP函数,以便在我调用它时为它连接它吗?
这是我的PHP函数
public function getCustomerinfoByCompanyID($itemID) {
$stmt = mysqli_prepare($this->connection, "SELECT * FROM $this->tablename where CompanyID=?");
$this->throwExceptionOnError();
mysqli_stmt_bind_param($stmt, 'i', $itemID);
$this->throwExceptionOnError();
mysqli_stmt_execute($stmt);
$this->throwExceptionOnError();
$rows = array();
mysqli_stmt_bind_result($stmt, $row->CustID, $row->CompanyID, $row->FirstName, $row->Surname, $row->CellNo, $row->Email);
while (mysqli_stmt_fetch($stmt)) {
$rows[] = $row;
$row = new stdClass();
mysqli_stmt_bind_result($stmt, $row->CustID, $row->CompanyID, $row->FirstName, $row->Surname, $row->CellNo, $row->Email);
}
mysqli_stmt_free_result($stmt);
mysqli_close($this->connection);
return $rows;
}
答案 0 :(得分:3)
您可以将查询更改为
SELECT *,CONCAT(FirstName,' ',Surname) as FullName FROM $this->tablename where CompanyID=?
然后你改变
mysqli_stmt_bind_result($stmt, $row->CustID, $row->CompanyID, $row->FirstName, $row->Surname, $row->CellNo, $row->Email);
类似
mysqli_stmt_bind_result($stmt, $row->CustID, $row->CompanyID, $row->FullName, $row->CellNo, $row->Email);
你有一栏