sql问题(周排行,月排行)
编写数据库表的时候遇到一个问题,我这个网站需要有周排行月排行,哪个大神知道这个表怎么设计 数据量不大,直接存就行,你不能太懒,可以拿出设计,让大家提意见。 可以在表中添加一个当前为第几周的字段 yunnysunny 发表于 2013-10-26 10:51 static/image/common/back.gif可以在表中添加一个当前为第几周的字段
好久没上了 解决了 用的sql的week和month函数,谢谢哈
:victory: {:soso_e182:} 貌似用函数,效率不是很高啊,而且索引页起不到什么效果啊~~~ 你可以用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];
} 老才...有大牛告诉你喽,,,,
页:
[1]