2

I created 2 textension in magento along with 2 different tables. First extension store data in table-1 while second second extension store data in table-2. Now i want to display data in first extension by LeftJoin. It show data without leftjoin from first table but not showing data with leftjoin from both the tables.
This code in block.php

public function methodblock() { $collection = Mage::getModel('test/test')->getCollection(); $returnCollection = $collection->getSelect() ->joinLeft('magento_answer', 'id_pfay_test=question_id', array('*'), null , 'left'); return $returnCollection; } 

On Layout side. dislplaydata.phtml

<?php $collection = $this->testmethodblock(); foreach($collection as $rows { echo $rows ->getData('name'); } 
3
  • What errors are you getting? See if this answer helps: stackoverflow.com/a/19401573/1076075 Commented Dec 30, 2014 at 12:40
  • I is not displaying any error. when i echo $returnCollection. It gives this query. SELECT main_table.*, magento_answer.* FROM magento_pfay_test AS main_table LEFT JOIN magento_answer ON id_pfay_test=question_id . This query is running properly on mysql db. Commented Dec 30, 2014 at 12:47
  • try to print query and check where is the problem. before return function write echo $collection->getSelect();exit; Commented Dec 30, 2014 at 14:03

1 Answer 1

2

I Got the answer. I use the custom query which works for me.

$resource = Mage::getSingleton('core/resource'); $readConnection = $resource->getConnection('core_read'); $qTable = $resource->getTableName('pfay_test'); $aTable = $resource->getTableName('answer/answer'); $query = 'SELECT * FROM '.$qTable.' q left join '.$aTable.' a ON a.question_id=q.id_pfay_test'; $results = $readConnection->fetchAll($query); return $results; 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.