I am trying to pull amounts from the pay column of the loads table for the last 7 days and echo it to show results. i have tried several different way to do this and i am stumped.
<?PHP
$startDate = date("Y-m-d");
$endDate = strtotime(date("Y-m-d"). "-7 days");
$lsql ="SELECT * FROM loads WHERE created_at BETWEEN '$startDate 00:00:00' AND '$endDate 23:59:59'";
foreach ($link->query($lsql) as $ldata) {
echo $ldata['pay'];
}
?>
You probably just need to do:
SELECT * FROM loads WHERE created_at >= CURDATE() - INTERVAL 7 DAY;
directly from MySQL query. Or use DATE_SUB like:
SELECT * FROM loads WHERE created_at >= DATE_SUB(CURDATE(), INTERVAL 7 DAY)
If CURDATE()
is not working, change it to NOW()
like:
SELECT * FROM loads WHERE created_at >= DATE_SUB(NOW(), INTERVAL 7 DAY)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.