1

I have two tables. Both of them have a column named 'title'. When I use the following code snippet to join two tables, I can't access one of the title column.

    $select = $this->select(Zend_Db_Table::SELECT_WITH_FROM_PART);
    $select->setIntegrityCheck(false);
    $select->join("service","service.id = lecture.service_id");
    return $select;

is there a way to access both columns?

4

2 回答 2

9

您需要重命名其中一列,使其不与另一列冲突。如果将数组作为可选的第三个参数传递给 join(),则可以指定要从连接表中检索哪些列。如果数组中的一个或多个条目被散列,则散列键将用作属性名称。使用下面的代码,您可以在查询结果中将服务表的标题列称为“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;
于 2010-12-21T02:53:57.137 回答
1
$select = $this->select();
$select->from(array('t'=>'table1'), array('table_title AS title_first','table_sendo_colun','table_third_colun'));
$select->setIntegrityCheck(false);
$select->join("service","service.id = t.service_id");
return $select;

也许它可以完成这项工作。

问候。

于 2010-08-19T14:39:37.120 回答