There is a table in which records of financial transactions are stored.
The first entry was made for example in November: 2016-11-10
Last entry was made in April: 2017-04-19
It is necessary to display a list of months where there are financial transactions in this way: November, December, January, February, March, April.
Then for each month you need to display the total amount of all payments.

$OplafirstSQL = mysql_query ("SELECT * FROM dfort_finance_client WHERE contract = '$id_contract' ORDER BY dfort_finance_client . datesort ASC"); $Oplafirst = mysql_fetch_array ($OplafirstSQL); $OplasecondSQL = mysql_query ("SELECT * FROM dfort_finance_client WHERE contract = '$id_contract' ORDER BY dfort_finance_client . datesort DESC"); $Oplasecond = mysql_fetch_array ($OplasecondSQL); echo "Первая оплата: ".$Oplafirst['datesort']."<br>Последняя оплата: ".$Oplasecond['datesort']."<br>"; 
  • show what you did - L. Vadim

1 answer 1

For MySQL, you can use the horror type

 SELECT LPAD(MONTH(MIN(`date`)),2,'0'), SUM(`payment`) FROM `table` GROUP BY MONTH(`date`) 

The language is adjusted by setting lc_time_names.

  • '$ OReqSQL = mysql_query ("SELECT MONTHNAME (MIN ( datesort )) FROM dfort_finance_client GROUP BY MONTH ( datesort )"); $ Req = mysql_fetch_array ($ OReqSQL); ' and how to get it out - Anton Batrak
  • Yes, as it should, and output ... - Akina
  • It turned out like this: $OReqSQL = mysql_query ("SELECT MONTHNAME(MIN( datesort )) FROM dfort_finance_client` WHERE contract = '$ id_contract' GROUP BY MONTH ( datesort ) ORDER BY dfort_finance_client. Datesort ASC"); while ($ Req = mysql_fetch_array ($ OReqSQL)) {echo $ Req [0]. "<br>"; } `And how can we make the conclusion of the month by the number and not the name in English? - Anton Batrak
  • How to make a month's conclusion by number You will not believe ... to use not MONTHNAME (), but MONTH () ... - Akina
  • A two-digit number is needed as a type: 01, 02, 03, 11, 12 and it outputs 1,2,3,4,11,12 - Anton Batrak