Display data from multiple database tables to frontend Unicorn Meta Zoo #1: Why another podcast? Announcing the arrival of Valued Associate #679: Cesar ManaraMagento2 Need to build Grid with multiple table collection using UI ComponentsUnit Test for overwrite collection class in magento2How to add date filed in admin & show on front in magento2Magento 2 : resource name is not definedError in Grid magento 2 Fatal error: Method MagentoUiTemplateEngineXhtmlResult::__toString()Magento 2: Plugin class does not existError during compilation in magento 2.2.2Magento2 REST API get all customers detailsPHP Fatal error: Uncaught TypeError: Argument 1 passed to Magento\Framework\Data\Collection\AbstractDb::setConnection() must implement interfaceIncompatible argument type error during compilation in Magento2.2.5?Error Database Magento 2.3 migration from localhost to server
"Whatever a Russian does, they end up making the Kalashnikov gun"? Are there any similar proverbs in English?
Why didn't the Space Shuttle bounce back into space as many times as possible so as to lose a lot of kinetic energy up there?
How to get even lighting when using flash for group photos near wall?
Retract an already submitted recommendation letter (written for an undergrad student)
Are these square matrices always diagonalisable?
What's parked in Mil Moscow helicopter plant?
Multiple options vs single option UI
Can you stand up from being prone using Skirmisher outside of your turn?
As an international instructor, should I openly talk about my accent?
finding a tangent line to a parabola
How to avoid introduction cliches
What was Apollo 13's "Little Jolt" after MECO?
Second order approximation of the loss function (Deep learning book, 7.33)
Does Feeblemind produce an ongoing magical effect that can be dispelled?
Could moose/elk survive in the Amazon forest?
Expansion//Explosion and Siren Stormtamer
All ASCII characters with a given bit count
How to not starve gigantic beasts
Do I need to protect SFP ports and optics from dust/contaminants? If so, how?
Are there moral objections to a life motivated purely by money? How to sway a person from this lifestyle?
Mistake in years of experience in resume?
A faster way to compute the largest prime factor
A Paper Record is What I Hamper
What ability score does a Hexblade's Pact Weapon use for attack and damage when wielded by another character?
Display data from multiple database tables to frontend
Unicorn Meta Zoo #1: Why another podcast?
Announcing the arrival of Valued Associate #679: Cesar ManaraMagento2 Need to build Grid with multiple table collection using UI ComponentsUnit Test for overwrite collection class in magento2How to add date filed in admin & show on front in magento2Magento 2 : resource name is not definedError in Grid magento 2 Fatal error: Method MagentoUiTemplateEngineXhtmlResult::__toString()Magento 2: Plugin class does not existError during compilation in magento 2.2.2Magento2 REST API get all customers detailsPHP Fatal error: Uncaught TypeError: Argument 1 passed to Magento\Framework\Data\Collection\AbstractDb::setConnection() must implement interfaceIncompatible argument type error during compilation in Magento2.2.5?Error Database Magento 2.3 migration from localhost to server
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
How to get data from 2 database tables and show them in the custom frontend page? I have been looking for the tutorials, so far what i get is creating SQL Left Join in the Collection.php
(even though i do not know whether this is working or not)
<?php
namespace NamespaceModulenameModelResourceModulename;
use MagentoFrameworkModelResourceModelDbCollectionAbstractCollection;
class Collection extends AbstractCollection
/**
* Define model & resource model
*/
const YOUR_TABLE = 'tablename';
public function __construct(
MagentoFrameworkDataCollectionEntityFactoryInterface $entityFactory,
PsrLogLoggerInterface $logger,
MagentoFrameworkDataCollectionDbFetchStrategyInterface $fetchStrategy,
MagentoFrameworkEventManagerInterface $eventManager,
MagentoStoreModelStoreManagerInterface $storeManager,
MagentoFrameworkDBAdapterAdapterInterface $connection = null,
MagentoFrameworkModelResourceModelDbAbstractDb $resource = null
)
$this->_init(
'NamespaceModulenameModelModulename',
'NamespaceModulenameModelResourceModulename'
);
parent::__construct(
$entityFactory, $logger, $fetchStrategy, $eventManager, $connection,
$resource
);
$this->storeManager = $storeManager;
protected function _initSelect()
parent::_initSelect();
$this->getSelect()->joinLeft(
['secondTable' => $this->getTable('tablename')],
'main_table.columnname = secondTable.columnname',
['columnname1','columnname2','columnname3']
);
?>
magento2 database
add a comment |
How to get data from 2 database tables and show them in the custom frontend page? I have been looking for the tutorials, so far what i get is creating SQL Left Join in the Collection.php
(even though i do not know whether this is working or not)
<?php
namespace NamespaceModulenameModelResourceModulename;
use MagentoFrameworkModelResourceModelDbCollectionAbstractCollection;
class Collection extends AbstractCollection
/**
* Define model & resource model
*/
const YOUR_TABLE = 'tablename';
public function __construct(
MagentoFrameworkDataCollectionEntityFactoryInterface $entityFactory,
PsrLogLoggerInterface $logger,
MagentoFrameworkDataCollectionDbFetchStrategyInterface $fetchStrategy,
MagentoFrameworkEventManagerInterface $eventManager,
MagentoStoreModelStoreManagerInterface $storeManager,
MagentoFrameworkDBAdapterAdapterInterface $connection = null,
MagentoFrameworkModelResourceModelDbAbstractDb $resource = null
)
$this->_init(
'NamespaceModulenameModelModulename',
'NamespaceModulenameModelResourceModulename'
);
parent::__construct(
$entityFactory, $logger, $fetchStrategy, $eventManager, $connection,
$resource
);
$this->storeManager = $storeManager;
protected function _initSelect()
parent::_initSelect();
$this->getSelect()->joinLeft(
['secondTable' => $this->getTable('tablename')],
'main_table.columnname = secondTable.columnname',
['columnname1','columnname2','columnname3']
);
?>
magento2 database
what is the issue available after use above query?
– Rakesh Jesadiya
Oct 25 '16 at 4:55
@Rakesh well that query is an answer from magento.stackexchange.com/a/124204/44801, but that was for creating admin grid that only leave Collection and di.xml, whereas what i need is display data to the frontend page. So i haven't tried above code
– Seventh St
Oct 25 '16 at 6:52
add a comment |
How to get data from 2 database tables and show them in the custom frontend page? I have been looking for the tutorials, so far what i get is creating SQL Left Join in the Collection.php
(even though i do not know whether this is working or not)
<?php
namespace NamespaceModulenameModelResourceModulename;
use MagentoFrameworkModelResourceModelDbCollectionAbstractCollection;
class Collection extends AbstractCollection
/**
* Define model & resource model
*/
const YOUR_TABLE = 'tablename';
public function __construct(
MagentoFrameworkDataCollectionEntityFactoryInterface $entityFactory,
PsrLogLoggerInterface $logger,
MagentoFrameworkDataCollectionDbFetchStrategyInterface $fetchStrategy,
MagentoFrameworkEventManagerInterface $eventManager,
MagentoStoreModelStoreManagerInterface $storeManager,
MagentoFrameworkDBAdapterAdapterInterface $connection = null,
MagentoFrameworkModelResourceModelDbAbstractDb $resource = null
)
$this->_init(
'NamespaceModulenameModelModulename',
'NamespaceModulenameModelResourceModulename'
);
parent::__construct(
$entityFactory, $logger, $fetchStrategy, $eventManager, $connection,
$resource
);
$this->storeManager = $storeManager;
protected function _initSelect()
parent::_initSelect();
$this->getSelect()->joinLeft(
['secondTable' => $this->getTable('tablename')],
'main_table.columnname = secondTable.columnname',
['columnname1','columnname2','columnname3']
);
?>
magento2 database
How to get data from 2 database tables and show them in the custom frontend page? I have been looking for the tutorials, so far what i get is creating SQL Left Join in the Collection.php
(even though i do not know whether this is working or not)
<?php
namespace NamespaceModulenameModelResourceModulename;
use MagentoFrameworkModelResourceModelDbCollectionAbstractCollection;
class Collection extends AbstractCollection
/**
* Define model & resource model
*/
const YOUR_TABLE = 'tablename';
public function __construct(
MagentoFrameworkDataCollectionEntityFactoryInterface $entityFactory,
PsrLogLoggerInterface $logger,
MagentoFrameworkDataCollectionDbFetchStrategyInterface $fetchStrategy,
MagentoFrameworkEventManagerInterface $eventManager,
MagentoStoreModelStoreManagerInterface $storeManager,
MagentoFrameworkDBAdapterAdapterInterface $connection = null,
MagentoFrameworkModelResourceModelDbAbstractDb $resource = null
)
$this->_init(
'NamespaceModulenameModelModulename',
'NamespaceModulenameModelResourceModulename'
);
parent::__construct(
$entityFactory, $logger, $fetchStrategy, $eventManager, $connection,
$resource
);
$this->storeManager = $storeManager;
protected function _initSelect()
parent::_initSelect();
$this->getSelect()->joinLeft(
['secondTable' => $this->getTable('tablename')],
'main_table.columnname = secondTable.columnname',
['columnname1','columnname2','columnname3']
);
?>
magento2 database
magento2 database
edited Oct 25 '16 at 6:58
Seventh St
asked Oct 25 '16 at 4:10
Seventh StSeventh St
40221025
40221025
what is the issue available after use above query?
– Rakesh Jesadiya
Oct 25 '16 at 4:55
@Rakesh well that query is an answer from magento.stackexchange.com/a/124204/44801, but that was for creating admin grid that only leave Collection and di.xml, whereas what i need is display data to the frontend page. So i haven't tried above code
– Seventh St
Oct 25 '16 at 6:52
add a comment |
what is the issue available after use above query?
– Rakesh Jesadiya
Oct 25 '16 at 4:55
@Rakesh well that query is an answer from magento.stackexchange.com/a/124204/44801, but that was for creating admin grid that only leave Collection and di.xml, whereas what i need is display data to the frontend page. So i haven't tried above code
– Seventh St
Oct 25 '16 at 6:52
what is the issue available after use above query?
– Rakesh Jesadiya
Oct 25 '16 at 4:55
what is the issue available after use above query?
– Rakesh Jesadiya
Oct 25 '16 at 4:55
@Rakesh well that query is an answer from magento.stackexchange.com/a/124204/44801, but that was for creating admin grid that only leave Collection and di.xml, whereas what i need is display data to the frontend page. So i haven't tried above code
– Seventh St
Oct 25 '16 at 6:52
@Rakesh well that query is an answer from magento.stackexchange.com/a/124204/44801, but that was for creating admin grid that only leave Collection and di.xml, whereas what i need is display data to the frontend page. So i haven't tried above code
– Seventh St
Oct 25 '16 at 6:52
add a comment |
1 Answer
1
active
oldest
votes
here is a sample for join to product collection
protected $productCollectionFactory;
public function __construct(
.....
MagentoCatalogModelResourceModelProductCollectionFactory $productCollectionFactory,
...
)
$this->productCollectionFactory = $productCollectionFactory;
....
public function getCollection()
$collection = $this->productCollectionFactory->create();
$collection->getSelect()->joinLeft(
['productsold'=>$collection->getTable('productsold')],
'e.entity_id = productsold.product_id',
['offsite'=>'productsold.off_sold','soldlabel'=>'productsold.label','soldid'=>'productsold.id']);
return $collection;
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "479"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f142452%2fdisplay-data-from-multiple-database-tables-to-frontend%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
here is a sample for join to product collection
protected $productCollectionFactory;
public function __construct(
.....
MagentoCatalogModelResourceModelProductCollectionFactory $productCollectionFactory,
...
)
$this->productCollectionFactory = $productCollectionFactory;
....
public function getCollection()
$collection = $this->productCollectionFactory->create();
$collection->getSelect()->joinLeft(
['productsold'=>$collection->getTable('productsold')],
'e.entity_id = productsold.product_id',
['offsite'=>'productsold.off_sold','soldlabel'=>'productsold.label','soldid'=>'productsold.id']);
return $collection;
add a comment |
here is a sample for join to product collection
protected $productCollectionFactory;
public function __construct(
.....
MagentoCatalogModelResourceModelProductCollectionFactory $productCollectionFactory,
...
)
$this->productCollectionFactory = $productCollectionFactory;
....
public function getCollection()
$collection = $this->productCollectionFactory->create();
$collection->getSelect()->joinLeft(
['productsold'=>$collection->getTable('productsold')],
'e.entity_id = productsold.product_id',
['offsite'=>'productsold.off_sold','soldlabel'=>'productsold.label','soldid'=>'productsold.id']);
return $collection;
add a comment |
here is a sample for join to product collection
protected $productCollectionFactory;
public function __construct(
.....
MagentoCatalogModelResourceModelProductCollectionFactory $productCollectionFactory,
...
)
$this->productCollectionFactory = $productCollectionFactory;
....
public function getCollection()
$collection = $this->productCollectionFactory->create();
$collection->getSelect()->joinLeft(
['productsold'=>$collection->getTable('productsold')],
'e.entity_id = productsold.product_id',
['offsite'=>'productsold.off_sold','soldlabel'=>'productsold.label','soldid'=>'productsold.id']);
return $collection;
here is a sample for join to product collection
protected $productCollectionFactory;
public function __construct(
.....
MagentoCatalogModelResourceModelProductCollectionFactory $productCollectionFactory,
...
)
$this->productCollectionFactory = $productCollectionFactory;
....
public function getCollection()
$collection = $this->productCollectionFactory->create();
$collection->getSelect()->joinLeft(
['productsold'=>$collection->getTable('productsold')],
'e.entity_id = productsold.product_id',
['offsite'=>'productsold.off_sold','soldlabel'=>'productsold.label','soldid'=>'productsold.id']);
return $collection;
answered Oct 25 '16 at 4:59
Qaisar SattiQaisar Satti
27.2k1258110
27.2k1258110
add a comment |
add a comment |
Thanks for contributing an answer to Magento Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f142452%2fdisplay-data-from-multiple-database-tables-to-frontend%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
what is the issue available after use above query?
– Rakesh Jesadiya
Oct 25 '16 at 4:55
@Rakesh well that query is an answer from magento.stackexchange.com/a/124204/44801, but that was for creating admin grid that only leave Collection and di.xml, whereas what i need is display data to the frontend page. So i haven't tried above code
– Seventh St
Oct 25 '16 at 6:52