Hi,
In order to solve my problem, I did this (I hope that help to others):
- in onScriptinit event, I did create a temporary table with year lists:
sc_exec_sql(“CREATE TEMPORARY TABLE AnosList (
ano_sel YEAR NOT NULL,
ano_mos YEAR NOT NULL)”);
$sql_insert = "INSERT INTO AnosList VALUES ";
$min = 5;
$max = 5;
$ano = intval(date(‘Y’));
for ($i=$ano-$min; $i<=$ano+$max; $i++) {
$sql_insert.=’(’.$i.’,’.$i.’),’;
}
$sql_insert=trim($sql_insert, ‘,’);
echo $sql_insert;
sc_exec_sql($sql_insert);
- change the field to select type, in “Lookup Settings”, put a select for the temporary table:
select ano_sel, ano_mos from AnosList
The minor issue with this option, is: when the form is saved, appear a error message informing that fields is not exists but run fine.
Other way to create the list (to prevent the minor issue) is create a view in SQL with union selects, something like this:
CREATE
ALGORITHM = UNDEFINED
DEFINER = aymg01
@%
SQL SECURITY DEFINER
VIEW Anos
AS
SELECT
YEAR((CURDATE() - INTERVAL 1 YEAR)) AS ano_val
,
YEAR((CURDATE() - INTERVAL 1 YEAR)) AS ano_mos
UNION SELECT
YEAR(CURDATE()) AS `year(curdate())`,
YEAR(CURDATE()) AS `year(curdate())`
UNION SELECT
YEAR((CURDATE() + INTERVAL 1 YEAR)) AS `year(date_add(curdate(), interval 1 year))`,
YEAR((CURDATE() + INTERVAL 1 YEAR)) AS `year(date_add(curdate(), interval 1 year))`
Regards,
AYMG