Skip to main content
deleted 17 characters in body
Source Link
fmsthird
  • 4.6k
  • 4
  • 18
  • 42

This is not really a recommended way but I think you can write a custom Mysql Query (Without Using Model).

You can try like this:

$objectManager = \Magento\Framework\App\ObjectManager::getInstance(); 
$resource = $objectManager->get('Magento\Framework\App\ResourceConnection');
$connection = $resource->getConnection();
$tableName = $resource->getTableName('custom_table'); 
 
//Select Data from custom_table
$sql = "Select * FROM " . $tableName;
$result = $connection->fetchAll($sql);  

And you can loop the result in your select field options like this:

$fieldset->addFieldforeach(
     "test2",
 $result as $key => "select",$option){
     [
     $options[] = ["value" => $key,"label"     =>      __("Test 2"$option)],
         "name"      => }

$fieldset->addField(
     "test2",
      "select",
   "values"  [
  =>      [
 "label"     =>      foreach__($result as $key =>"Test $option2"){,
         "name"     ["value" => $key,"label" => __($option)],
    "test2",
        }
 "values"    =>    ][$options]
     ]
 );
   

Adding here: Fetch database custom table using custom model and Resourcemodel

This is not really a recommended way but I think you can write a custom Mysql Query (Without Using Model).

You can try like this:

$objectManager = \Magento\Framework\App\ObjectManager::getInstance(); 
$resource = $objectManager->get('Magento\Framework\App\ResourceConnection');
$connection = $resource->getConnection();
$tableName = $resource->getTableName('custom_table'); 
 
//Select Data from custom_table
$sql = "Select * FROM " . $tableName;
$result = $connection->fetchAll($sql);  

And you can loop the result in your select field options like this:

$fieldset->addField(
     "test2",
     "select",
     [
         "label"     =>      __("Test 2"),
         "name"      =>      "test2",
         "values"    =>      [
            foreach($result as $key => $option){
              ["value" => $key,"label" => __($option)],
            }
         ]
     ]
 );
   

Adding here: Fetch database custom table using custom model and Resourcemodel

This is not really a recommended way but I think you can write a custom Mysql Query (Without Using Model).

You can try like this:

$objectManager = \Magento\Framework\App\ObjectManager::getInstance(); 
$resource = $objectManager->get('Magento\Framework\App\ResourceConnection');
$connection = $resource->getConnection();
$tableName = $resource->getTableName('custom_table'); 
 
//Select Data from custom_table
$sql = "Select * FROM " . $tableName;
$result = $connection->fetchAll($sql);  

And you can loop the result in your select field options like this:

foreach($result as $key => $option){
      $options[] = ["value" => $key,"label" => __($option)],
}

$fieldset->addField(
     "test2",
     "select",
     [
         "label"     =>      __("Test 2"),
         "name"      =>      "test2",
         "values"    =>    [$options]
     ]
 );
   

Adding here: Fetch database custom table using custom model and Resourcemodel

Source Link
fmsthird
  • 4.6k
  • 4
  • 18
  • 42

This is not really a recommended way but I think you can write a custom Mysql Query (Without Using Model).

You can try like this:

$objectManager = \Magento\Framework\App\ObjectManager::getInstance(); 
$resource = $objectManager->get('Magento\Framework\App\ResourceConnection');
$connection = $resource->getConnection();
$tableName = $resource->getTableName('custom_table'); 
 
//Select Data from custom_table
$sql = "Select * FROM " . $tableName;
$result = $connection->fetchAll($sql);  

And you can loop the result in your select field options like this:

$fieldset->addField(
     "test2",
     "select",
     [
         "label"     =>      __("Test 2"),
         "name"      =>      "test2",
         "values"    =>      [
            foreach($result as $key => $option){
              ["value" => $key,"label" => __($option)],
            }
         ]
     ]
 );
   

Adding here: Fetch database custom table using custom model and Resourcemodel