从日期中提取YEAR并对其进行分组

时间:2022-08-25 10:26:29

i have a small problem.

我有一个小问题。

$fetch_years=mysqli_query($connect, "SELECT date, YEAR(shift.date) as year FROM shift");
while($years = mysqli_fetch_array($fetch_years))
{
    echo ' '.$years['date'].' <br/> '.$year.' <br/><br/>';

I try to extract the year from the date field and group it. The part '.$years['date'].'
and missing group by is only for the test

我尝试从日期字段中提取年份并对其进行分组。部分'。$ years ['date']。'并且缺少group by仅用于测试

That's my result:

这是我的结果:

2016-10-13
2017

2017-11-04
2017

2017-11-10
2017

What's wrong?

1 个解决方案

#1


0  

In the echo command, you take $years['date'], which comes from the query results and $year, which comes from... ?

在echo命令中,你需要$ years ['date'],它来自查询结果和$ year,它来自......?

Instead of $year, do $years['year'] to get the results form your query.

而不是$ year,用$ years ['year']来获得查询结果。

echo ' '.$years['date'].' <br/> '.$years['year'].' <br/><br/>';

For your question, you should have put tag PHP as well.

对于你的问题,你也应该把标记PHP。

#1


0  

In the echo command, you take $years['date'], which comes from the query results and $year, which comes from... ?

在echo命令中,你需要$ years ['date'],它来自查询结果和$ year,它来自......?

Instead of $year, do $years['year'] to get the results form your query.

而不是$ year,用$ years ['year']来获得查询结果。

echo ' '.$years['date'].' <br/> '.$years['year'].' <br/><br/>';

For your question, you should have put tag PHP as well.

对于你的问题,你也应该把标记PHP。