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?

  • in magento1 or magento2 and what is table name ? – Ansar Husain Aug 16 '18 at 5:02
  • Itś Magento 2 and the name of the table is 'mgfx_customer_entity' – Nuno Sousa Aug 16 '18 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 – Mohamed El Mrabet Aug 16 '18 at 5:59
  • Só, how can I do it? I’m a newbie – Nuno Sousa Aug 16 '18 at 6:05
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();
    }
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.