- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我现在将使用 Laravel 4.2 的归档系统(列表)年份和月份恢复我的文章。
我每年和每月都能毫无问题地检索我的元素(见下文)
这是我使用查询生成器 Laravel 的 Controller
public function index(){
$post_links = DB::table('posts')
->select(DB::raw('YEAR(created_at) year, MONTH(created_at) month, MONTHNAME(created_at) month_name, COUNT(*) post_count'))
->groupBy('year')
->groupBy('month')
->orderBy('year', 'desc')
->orderBy('month', 'desc')
->get();
return View::make('home.index')->with(array(
'post_links'=>$post_links,
));
}
还有我的看法
<ul id="show-year">
@foreach($post_links as $link)
{{--{{dd($link)}}--}}
{{--Show year--}}
<li>
<a title="" href="#">
<span>
<strong>{{$link->year}}</strong></a> <span class="post-count">{{$link->post_count}}</span><i class="fa fa-arrow-right"></i>
</span>
</li>
</a>
{{--show month--}}
<ul id="show-month">
<li class="month-content">
<a href="">
<span>
<strong>{{$link->month_name}}</strong>
</span>
</a>
</li>
</ul>
</li>
@endforeach
</ul>
我恢复了我的数据数年和数月,但它以这种方式每个月为她增加了一年
2015 ( 21 )- 五月 (2)- 四月 (3)- 三月 (5)- 二月 (1)- 一月 (10)2016 (10)- 十二月 (6)- 十一月(4)
我不明白为什么它不将我分组在同一年,而是每次为每个月生成一个新的年份条目。
感谢您的帮助。
最佳答案
为了在某种导航面板中生成链接,您可以在数据库端完成大部分处理,而不是使用这样的查询来获取所有博客文章记录
SELECT YEAR(created_at) year,
MONTH(created_at) month,
MONTHNAME(created_at) month_name,
COUNT(*) post_count
FROM post
GROUP BY year, MONTH(created_at)
ORDER BY year DESC, month DESC;
输出:
| YEAR | MONTH | MONTH_NAME | POST_COUNT |
------------------------------------------
| 2013 | 5 | May | 5 |
| 2013 | 4 | April | 3 |
| 2013 | 3 | March | 4 |
| 2013 | 2 | February | 3 |
| 2013 | 1 | January | 2 |
| 2012 | 12 | December | 2 |
| 2012 | 11 | November | 3 |
类似这样的代码
$links = DB::table('post')
->select(DB::raw('YEAR(created_at) year, MONTH(created_at) month, MONTHNAME(created_at) month_name, COUNT(*) post_count'))
->groupBy('year')
->groupBy('month')
->orderBy('yea`enter code here`r', 'desc')
->orderBy('month', 'desc')
->get();
原始解决方案是 here
关于php - Laravel 按年份和月份生成存档帖子,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35279386/
我正在完成一项让我难堪好几天的学校作业。任务是使用 View (VAvailableGolfers) 将与从组合框中选择的给定事件/年份无关的高尔夫球手填充到列表框中。以下是表中的数据: 那么,表单上
给定一年和那年的某一天,我如何获得完整的日期?例如:60/2014 = 2014 年 3 月 1 日 和 61/2016 = 2016 年 3 月 1 日 注释:-年和日可以作为单独的参数传递。 -结
我正在使用 ExtJS 3,当我想为日期选择器选择日期时,我只能设置日期和月份(通过左/右箭头)。月/年面板会放下来,但很快就会消失,因此无法选择它。这是最能描述该行为的桌面记录:http://fli
我正在尝试获取用于在 div 中显示当前月份和年份的 jquery 或 java 脚本代码,但目前还不能。我的意思是我想以这种格式显示当前的月份和年份:October 2012 这样每个月我都不需要编
我有这段代码可以从数据库中获取一个字段: $end_date=$row1['end_date']; 如果我打印它,它会给我这样的信息:25-09-2012我需要的是获取月份值、年份和日期。类似于: $
我有两个格式如下的数据集: df1 #> Artist Album Year #> 1 Beatles Sgt. Pepper's 1967 #>
我使用 jQuery 验证插件和 maskedInput 插件对输入进行了自定义日期和时间验证。 有没有办法在自定义验证中进行验证以防止输入大于当前年份的年份? 我的代码: $("#date").ma
我在 xml 解析方面没有经验,所以也许我写的一些东西对某些人来说看起来很愚蠢,也许我的一些术语不太正确。请原谅。 我开发了一个Android应用程序,它需要解析来自YR.no的天气数据。 。该组织提
我需要当前年份,月份和日期为3个不同的变量。下面的代码给出了日期时间 val now = Calendar.getInstance().getTime() 2016年9月29日星期四18:27:38
在模态对话框中使用日期选择器,请不要在 Firefox 19.0.2 中使用更改月/年下拉列表,请参阅: http://jsfiddle.net/469zV/2/ HTML
我希望日期输入在年份有 4 位数字后停止输入。我尝试使用 HTML 中的 min 和 max 组件,但它仍然允许您键入删除第一个数字。参见示例 1。 请参阅示例 2 以了解可以输入超过 4 位数字的年
因此不同是基于唯一的月/年,而不仅仅是一个不同的月份(所以我希望 2011 年 1 月和 2012 年 1 月是不同的) // Test set of data List Compl
在 Programming in the Key of C# 中,作者给出了一个示例(附源代码),说明如何将日期(年、月、日 -- 数字)打包为 32 位整数。在示例中,作者将信息打包如下: int
这里我有一个任务,如果我写这样的代码,年份应该像 1947 年到 2016 年一样绑定(bind)在 DropdownList 中 1947 2016 拍了一整天 最佳答案 例如,
显然,我的 SQL 不是最好的,但我想做的是通过查找条目中的最大年份和月份来获取数据库中的最新日期。现在我有: select max(Month), max(Year) from posts wher
我试图弄清楚是否有任何 ID 发生在任何早年(即 dfo 中的 Duplicate 列)。如果是这样,我想将该行标记为重复行并包括 ID 首次出现的年份(即 Year_Duplicate)。 我确实有
我已经从 df 中提取了列列表,这些列是字符串类型,如下所示:1999-1(如 1999 年第一个月)。 我想删除 2000 年之前的所有列,因此我提取了列列表并使用列表理解来检查字符串的第一个字符是
日期时间是什么时候?我的 DateTimePicker 控件的源更改为 null,我想选择另一个日期,日历下拉列表默认为最后选择的月份和年份。 我正在为 DOB 使用 DateTimePicker,因
我正在获取系统当前日期并尝试在 TextView 中显示它。 尝试下面的代码后 private OnClickListener listener1 = new OnClickListener() {
我想使用 knockoutJS 库验证年份。我面临的问题是,当用户输入错误的年份时,不会对年份进行验证。以下是年份错误的情况。 (01/01/12 becomes 01/01/0012) (01/0
我是一名优秀的程序员,十分优秀!