Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR SQL

get last 3 years data in mysql

<?php  
$x = 1;
$tahun = 2022;
$data = array();
 
while($x <= 3) {

  array_push($data,($tahun));
  $tahun = $tahun-1;
  $x++;
} 

$hasil = implode(',',$data);
var_dump($hasil);

 $sql = "SELECT count(*) nilai FROM {$ref_table} WHERE emp_id = '{$emp_id}' AND flag_del = 'N'
            AND YEAR(begin_date) IN ($hasil)";


?>  
 
PREVIOUS NEXT
Tagged: #years #data #mysql
ADD COMMENT
Topic
Name
1+3 =