每小时从数据库中检索一个值并发送到另一个页面


retrieve single value from the database every hour and send to another page

我需要写一个每小时运行一次的php脚本,

因此,在我的数据库中,我有7个表,代表一周中的几天,如周日、周一、周二等,所有表都有25列,代表24小时,如凌晨1点、凌晨2点、凌晨3点等,还有一个时间戳列。

因此,现在我必须编写一个php脚本,它使用cron每小时运行一次这个脚本。

使用php date()函数可以获得各种格式的当前日期信息,而无需使用DB。

这是PHP手册的链接。

http://php.net/manual/en/function.date.php

一些示例直接来自链接的PHP手册页。

<?php
// set the default timezone to use. Available since PHP 5.1
date_default_timezone_set('UTC');

// Prints something like: Monday
echo date("l");
// Prints something like: Monday 8th of August 2005 03:12:46 PM
echo date('l jS 'of F Y h:i:s A');
// Prints: July 1, 2000 is on a Saturday
echo "July 1, 2000 is on a " . date("l", mktime(0, 0, 0, 7, 1, 2000));
/* use the constants in the format parameter */
// prints something like: Mon, 15 Aug 2005 15:12:46 UTC
echo date(DATE_RFC822);
// prints something like: 2000-07-01T00:00:00+00:00
echo date(DATE_ATOM, mktime(0, 0, 0, 7, 1, 2000));
?>

为什么不将DB设计更改为一个表?

创建表days(CCD_ 3 int(10)NOT NULL AUTO_INCREMENT,CCD_ 4 tinyint(1)NOT NULL,CCD_ 5 tinyint(2)NOT NULL,CCD_ 6 varchar(255)DEFAULT NULL,主键(days_id),唯一密钥days_daydays_daydays_hour));

然后只需查询:

$sql='从days选择days_value,其中days_day='。日期("W")并且CCD_ 14='。日期('H')。'极限1';

让事情变得容易多了。