Monthly numbering automatic

Put your suggestions here.
Post Reply
as100
Investor
Investor
Posts: 90
Joined: 25 Aug 2017, 11:01
Name: Lukasz
Location: Poland

Monthly numbering automatic

Post by as100 »

Hello, I need to make automatic monthly numbering. The field available in the system only supports annual. There is often a need to use the monthly one, I tried using SQL fields but it didn't work. Does anyone know a way or is there any plans to do so? That is, records related to the indicated date field numbered ascending and reset to zero for each month separately.
It is important that it is a date field, any date, and not e.g. the date of record creation.
enishemed
Posts: 651
Joined: 30 Oct 2017, 11:24
Name: Enis Hemedoglu
Location: Istanbul, Turkey
Company Name: SCORE DANISMANLIK
Contact:

Re: Monthly numbering automatic

Post by enishemed »

The following code should work.

Create a numeric field. [1112]
Create a date field. [1111]

Code: Select all

$item_month = date('Y-m', [1111]); //change Unix time to Y-m format
  
$info_query = db_query("select field_1112 as num, from_unixtime(field_1111, '%Y-%m') as month from app_entity_28 order by id desc limit 1,1");
$info = db_fetch_array($info_query);
$prev_item_num = $info['num']; //previous item number
$prev_item_month = $info['month']; //previous item month


//assign the new auto number
if($item_month == $prev_item_month)
{
  $new_item_num = $prev_item_num + 1;
}
else
{
  $new_item_num = 1;
}

//save the new auto number to db
$output_value = $new_item_num;
as100
Investor
Investor
Posts: 90
Joined: 25 Aug 2017, 11:01
Name: Lukasz
Location: Poland

Re: Monthly numbering automatic

Post by as100 »

How to assign a calculated value from the given code to a numeric field?
enishemed
Posts: 651
Joined: 30 Oct 2017, 11:24
Name: Enis Hemedoglu
Location: Istanbul, Turkey
Company Name: SCORE DANISMANLIK
Contact:

Re: Monthly numbering automatic

Post by enishemed »

This code assigns it.

Code: Select all

$output_value = $new_item_num;
as100 wrote: 22 Sep 2023, 14:09 How to assign a calculated value from the given code to a numeric field?
as100
Investor
Investor
Posts: 90
Joined: 25 Aug 2017, 11:01
Name: Lukasz
Location: Poland

Re: Monthly numbering automatic

Post by as100 »

It doesn't work, what type of field should I use for calculations?
enishemed
Posts: 651
Joined: 30 Oct 2017, 11:24
Name: Enis Hemedoglu
Location: Istanbul, Turkey
Company Name: SCORE DANISMANLIK
Contact:

Re: Monthly numbering automatic

Post by enishemed »

php code field
as100 wrote: 24 Sep 2023, 01:05 It doesn't work, what type of field should I use for calculations?
as100
Investor
Investor
Posts: 90
Joined: 25 Aug 2017, 11:01
Name: Lukasz
Location: Poland

Re: Monthly numbering automatic

Post by as100 »

I always get the value 1 in the numeric field of subsequent items. Not another value, increased by 1.
as100
Investor
Investor
Posts: 90
Joined: 25 Aug 2017, 11:01
Name: Lukasz
Location: Poland

Re: Monthly numbering automatic

Post by as100 »

And it doesn't transfer anything to the numeric field.
Post Reply