我有两张桌子.它们都有一个名为'title'的列.当我使用以下代码片段连接两个表时,我无法访问其中一个标题列.
$select = $this->select(Zend_Db_Table::SELECT_WITH_FROM_PART);
$select->setIntegrityCheck(false);
$select->join("service","service.id = lecture.service_id");
return $select;
Run Code Online (Sandbox Code Playgroud)
有没有办法访问两列?
小智 9
您需要重命名其中一列,以使其不与另一列冲突.如果将数组作为join()的可选第3个参数传递,则可以指定要从连接表中检索的列.如果对数组中的一个或多个条目进行哈希处理,则哈希键将用作属性名称.使用下面的代码,您可以在查询结果中将服务表的标题列称为"service_title".如果需要服务表中的其他列,请将它们添加到数组中,根据需要添加或不使用哈希.
$select = $this->select(Zend_Db_Table::SELECT_WITH_FROM_PART);
$select->setIntegrityCheck(false);
$select->join("service", "service.id = lecture.service_id",
array("service_title" => "service.title");
return $select;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3215 次 |
| 最近记录: |