Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

210
Visualizações
PHPMaker 2019 | Dynamic caption based on data in database

In PHPMaker (v2019) i have the following need:

Generate a caption for an column which contains a dynamic part - the year. Currently I'm using the system-date with following code:

$this->COLUMN_IN_DATABASE ->Caption .= "MyColumnName " . (date("Y") + 0)

This works finde but i need change this to an value in the database. There is an column which contains the year and an month like this:

YYYY-MM

Therefore I need to extract the YYYY and use it in the caption.

Any ideas?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

The solution is:

Put the following code in the top of "PageLoad" event:

    ($YEAR = ExecuteScalar ("select DISTINCT (CAST((SUBSTR(YEARANDMONTH,0,4)) AS NUMBER(4))) YEAR FROM TABLE WHERE YEARANDMONTH = (SELECT MAX(YEARANDMONTH) FROM TABLE )"));
    ($MONTHNUM= ExecuteScalar ("select DISTINCT (CAST((SUBSTR(YEARANDMONTH,6,2)) AS NUMBER(4))) MONTHNUMBER from TABLE WHERE YEARANDMONTH= (SELECT MAX(YEARANDMONTH) FROM TABLE )"));

Then, after that, you can use the results in every column caption of your choice like this: (We assume the result of the above mentioned SQL-result is "2021" as $YEAR and "5" as $MONTHNUM)

    $this->YEAR2 ->Caption .= "In two Years it will be the year " . (($YEAR)+2) . " and the current month number is " . ($MONTHNUM);

Then the caption if the "YEAR2"-column will be: "In two Years it will be the year 2023 and the month number is 5"

Extra: In my case I had in some columns the need to display the full month name based on the month number. So i have added the third line of code in the top section:

    ($MONTHNAME = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]);

And to display the month name the code is like this: (We assume the result of the above mentioned SQL-result is "2021" as $YEAR and "5" as $MONTHNUM)

    $this->YEAR2 ->Caption .= "In two Years it will be the year " . (($YEAR)+2) . " and the month name will be " . ($MONTHNAME[$MONTHNUM-1]);

Then the caption if the "YEAR2"-column will be: "In two Years it will be the year 2023 and the month name will be May"

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda