用户
 找回密码
 入住 CI 中国社区
搜索
查看: 2348|回复: 8
收起左侧

[HELP] sql问题(周排行,月排行)

[复制链接]
发表于 2013-10-21 11:04:02 | 显示全部楼层 |阅读模式
编写数据库表的时候遇到一个问题,我这个网站需要有周排行月排行,哪个大神知道这个表怎么设计
发表于 2013-10-26 09:24:17 | 显示全部楼层
数据量不大,直接存就行,你不能太懒,可以拿出设计,让大家提意见。
发表于 2013-10-26 10:51:46 | 显示全部楼层
可以在表中添加一个当前为第几周的字段
 楼主| 发表于 2013-10-28 15:56:03 | 显示全部楼层
yunnysunny 发表于 2013-10-26 10:51
可以在表中添加一个当前为第几周的字段

好久没上了 解决了 用的sql的week和month函数,谢谢哈
发表于 2013-10-28 16:01:00 | 显示全部楼层
 楼主| 发表于 2013-10-29 13:03:35 | 显示全部楼层
{:soso_e182:}
发表于 2013-10-29 14:03:43 | 显示全部楼层
貌似用函数,效率不是很高啊,而且索引页起不到什么效果啊~~~
发表于 2013-10-29 14:08:27 | 显示全部楼层
你可以用php算出时间,然后去查,PS
/**
     * 返回本周第一天
     *
     * @param int     $timestamp 某个星期的某一个时间戳,默认为当前时间
     * @param bollean $is_return_timestamp ,是否返回时间戳,否则返回时间格式
     *
     * @return int
     */
    private function _this_monday($timestamp = 0, $is_return_timestamp = true) {
        static $cache;
        $id = $timestamp . $is_return_timestamp;
        if (!isset($cache[$id])) {
            if (!$timestamp)
                $timestamp = time();
            $monday_date = date('Y-m-d', $timestamp - 86400 * date('w', $timestamp) + (date('w', $timestamp) > 0 ? 86400 : -/* 6*86400 */518400));
            if ($is_return_timestamp) {
                $cache[$id] = strtotime($monday_date);
            } else {
                $cache[$id] = $monday_date;
            }
        }
        return $cache[$id];
    }
   
    /**
     * 这个月的第一天
     *
     * @param int     $timestamp 某个月的某一个时间戳,默认为当前时间
     * @param bollean $is_return_timestamp ,是否返回时间戳,否则返回时间格式
     *
     * @return int
     */
   private function _month_firstday($timestamp = 0, $is_return_timestamp = true) {
        static $cache;
        $id = $timestamp . $is_return_timestamp;
        if (!isset($cache[$id])) {
            if (!$timestamp)
                $timestamp = time();
            $firstday = date('Y-m-d', mktime(0, 0, 0, date('m', $timestamp), 1, date('Y', $timestamp)));
            if ($is_return_timestamp) {
                $cache[$id] = strtotime($firstday);
            } else {
                $cache[$id] = $firstday;
            }
        }
        return $cache[$id];
    }
发表于 2013-10-29 14:09:37 | 显示全部楼层
老才...有大牛告诉你喽,,,,

本版积分规则