开发者

After joining tables with zend framework , it just show me one tables field

开发者 https://www.devze.com 2023-02-18 04:40 出处:网络
I have 2 tables product_category and product_sub_category The names of the fields are identical (id,name,explain,priority)

I have 2 tables product_category and product_sub_category

The names of the fields are identical (id,name,explain,priority)

product_sub_category has an foreign key to the product_category table with as product_category_id.

With the code below all I see is product_category fields

$select = $this->select("t1.* , t2.*")
  ->setIntegrityCheck(false)
  ->from(array("t1"=>$this->_name))
  ->joinInner(array("t2"=>'product_category'), 't2.id = t1.product_category_id')
  ->order(array('t1.priority'));
$res = $this->fetchAll($select);
return $res;

In $this->_name 开发者_如何学编程variable should be a string product_sub_category.

Why can I not see all fields from both tables?


MySQL will return the fields with the same name, so when ZF converts them to an array using the name as the index, the latter will overwrite the first. You'll need to give them aliases instead:

$this->select("t1.name AS category_name, t1.explain AS category_explain, t2.name AS subcategory_name")

and so on.

0

精彩评论

暂无评论...
验证码 换一张
取 消