function get_counter_barcode($year) { $db = new Database(); $counter = 0; $qList = "select * from counter_barcode where year= {$year} "; $rList = $db->sql_list($qList); if ($rList) { $counter = $rList['counter'] + 1; $updateBar = "UPDATE counter_barcode set counter={$counter} where year= {$year}"; $result = $db->sql_query($updateBar); } else { $createBar = "INSERT INTO counter_barcode(counter, year) VALUES (1,{$year})"; $result = $db->sql_query($createBar); $counter = 1; } return $counter; }