mysql - How to generate this sql table?
phpcn_u1582
phpcn_u1582 2017-05-27 17:39:01
0
2
555

As shown in the figure, this sql table is to be generated from 5 o'clock to 23 o'clock, with an interval of 15 minutes.

How to generate it?

phpcn_u1582
phpcn_u1582

reply all(2)
过去多啦不再A梦

Using PHP

$start = strtotime('20140227050000');
$end = strtotime('20140227230000');
$step = strtotime('1970-01-01 08:30:00');
$data = array();
while (($start+=$step) <= $end) {
    $data[] = array(
        's'=>date('Y-m-d H:i:s',($start-strtotime('1970-01-01 08:15:00'))),
        'e'=>date('Y-m-d H:i:s',$start)
    );
}
echo '<pre>';
var_dump($data);

Insert the data into the sql table

Another MYSQL one

-- 删除原有表
DROP TABLE IF EXISTS `t`;
-- 创建数据表
CREATE TABLE IF NOT EXISTS `t` (
    `s` varchar(255),
    `e` varchar(255)
);
-- 创建存储
create procedure protest()
begin
declare s int;
declare t int;
declare e int;
set s=UNIX_TIMESTAMP('20140227050000');
set t=900;
set e=UNIX_TIMESTAMP('20140227230000');
while s<e do
        set s=s+t;
    insert into t(`s`,`e`) values(FROM_UNIXTIME(s),FROM_UNIXTIME(s+t));
       set s=s+t;
end while;
end;
-- 调用存储
call protest();
-- 删除存储
drop procedure protest;
黄舟

Do you want to generate such a table structure? Or is this table already existing? Do you want to insert table content like this

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!