Menu

#89 Where put code to fill SelectOptions for custom field

None
open
nobody
None
1
2019-10-04
2019-10-02
Anonymous
No

Hi, I want to run these code in order to fill the options por custom field...

~~~~php
$Sql="Select fiscalid, nombre from mrbsfiscal where activo = 1 order by nombre asc ";
$fiscales = array();
$res = db()->query($sql);
for ($i = 0; ($row = $res->rowkeyed($i)); $i++)
{
$fiscales[$row['fiscalid']]=$row['nombre'];
}
$selectoptions['entry.fiscalid'] = $fiscales;*
~~~~

where should I put this?, If a put it in config.sys.inc I get the error:

  • Fatal error: Uncaught Error: Call to undefined function MRBS\db() in C:\Apache24\htdocs\desarrolloOgjRosario\web\config.inc.php:86 Stack trace: #0 C:\Apache24\htdocs\desarrolloOgjRosario\web\defaultincludes.inc(23): requireonce() #1 C:\Apache24\htdocs\desarrolloOgjRosario\web\day.php(4): require('C:\Apache24\htd...') #2 {main} thrown in C:\Apache24\htdocs\desarrolloOgjRosario\web\config.inc.php on line 86*

Thanks. !

Discussion

  • Campbell Morrison

    Can you explain more about what you are trying to do?

     
  • Anonymous

    Anonymous - 2019-10-03

    I have a custom field 'fiscalid'.
    I want to set the $Select_Options array with values from a table in the DataBase.
    I have found in another topic that it could be done in the 'create_field_entry_custom_field' function.
    I've tried with the code I put before, but I can't get it working.

     
  • Juan Pablo Beltramone

    Solved!
    Did a new method for the class BD:

     // La primera columna es el índice y la segunda el valor.
      public function query_2array($sql, $params = null)
      {
        $stmt = $this->query($sql, $params);
    
        $result = array();
        for ($i = 0; ($row = $stmt->row($i)); $i++)
        {
          $result[$row[0]] = $row[1];
        }
        return $result;
      }
    

    And then call it in the start of the edit_entry.php

    $sql="Select fiscal_id, nombre from mrbs_fiscal where activo = 1 order by nombre asc ";
    $select_options['entry.fiscal_id'] = db()->query_2array($sql);      
    

    Thanks.

     

    Last edit: Campbell Morrison 2019-10-04