0

I have two custom fields in my customer table, namely nickname and sponsor. I would like to create an sql query to select the two custom fields that I have in the table. What kind of query should I do?

asked Aug 16, 2018 at 4:55
4
  • in magento1 or magento2 and what is table name ? Commented Aug 16, 2018 at 5:02
  • Itś Magento 2 and the name of the table is 'mgfx_customer_entity' Commented Aug 16, 2018 at 5:27
  • Why you dont need to use repository or collection its eav entity its not simple to get with sql query and its not recomended Commented Aug 16, 2018 at 5:59
  • Só, how can I do it? I’m a newbie Commented Aug 16, 2018 at 6:05

1 Answer 1

0

You can use in your phtml file where you need .

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
 $customers = $objectManager->create('Magento\Customer\Model\ResourceModel\Customer\Collection')->load();
 foreach($customers as $customer){
 echo $customer->getNickname();
 echo $customer->Sponsor();
 }

or you can get these value by block using module like as

<?php
namespace Vendor\Module\Block;
use Magento\Framework\View\Element\Template;
class Customer extends Template
{ 
 protected $customerFactory;
 public function __construct( 
 \Magento\Customer\Model\CustomerFactory $customerFactory,
 )
 { 
 $this->customerFactory = $customerFactory;
 }
 public function getCustomerCollection(){
 $collection=$this->customerFactory->create()->getCollection();
 return $collection;
 }
}

And add below code in phtml file inside that module

$customers=$block->getCustomerCollection();
 foreach($customers as $customer){
 echo $customer->getNickname();
 echo $customer->Sponsor();
 }
answered Aug 16, 2018 at 6:14

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.