我有以下代码
$date = date("Y-m-d");
public function ip2_exists() {
global $db,$date;
$code = $db->select("imp","id",array("date"=>$date,"ip"=>$this->ip()));
if($code->num_rows<1){
return false;
}
else {
return true;
}
}
它收集当天的数据并且工作正常。但我想收集最近 5 天的日期。
如何在 PHP 中做到这一点?
最佳答案
尝试:
$date = date("Y-m-d");
public function ip2_exists()
{
global $db,$date;
// Used to keep count track
$countDays = 0;
// Default return of true
$checkedData = true;
while($countDays < 5)
{
$code = $db->select("imp","id",array("date"=>$date,"ip"=>$this->ip()));
if($code->num_rows < 1)
{
$checkedData = false;
}
$countDays++;
$date = date("Y-m-d", strtotime( $date." -1 day"));
}
return $checkedData;
}
关于php - 在 MySQL 中收集最近 5 天的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32001013/