mysql存储过程

…待完善
第一步:创建数据库

CREATE TABLE IF NOT EXISTS `usertest` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `username` varchar(32) NOT NULL,
  `password` varchar(32) NOT NULL,
  `time` datetime NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=5 ;
INSERT INTO `usertest` (`id`, `username`, `password`, `time`) VALUES
(1, 'zhangsan', 'aaabbbccc', '2012-07-30 07:37:06'),
(2, 'lisi', 'dddeeefff', '2012-07-30 07:37:06'),

第二步:创建存储过程

DELIMITER // 
CREATE PROCEDURE ptest()
BEGIN
SELECT 'Hello Word!' AS F;
END
//  
DELIMITER ;

…待完善

根据结束日期,获取一周的日期列表

/*
根据结束日期,获取一周的日期列表
*/
function getWeekArr($startDate,$date)
{
    $weekArr    =    array();
    $w             =    date('w',strtotime($date));
    $w            =    $w==0 ? 7 : $w;
    for($i=0;$i<$w;$i++)
    {
            $weekDate    =    date('Y-m-d',strtotime($date)-$i*86400);
            if($weekDate>=$startDate)
            {
                $weekArr[]    =    $weekDate;
            }
    }
    return $weekArr;
}
$startDate    =    '2012-06-10';
$date        =    '2012-07-10';
$result        =    getWeekArr($startDate,$date);
var_dump($result);
/*
array
  0 => string '2012-07-10' (length=10)
  1 => string '2012-07-09' (length=10)
*/