I have a table and use this to show me how many days the widgets have been in stock, this is the code I am using for this
x
$getWidgets = $db->prepare("SELECT * FROM widgettracker WHERE id=id");
$getWidgets->execute();
$widgets = $getWidgets->fetchAll();
foreach ($widgets as $widget) {
$startDate = new DateTime();
$endDate = new DateTime($widget['dadded']);
$diff = date_diff($endDate,$startDate);
$days = (int) $diff->format('%a');
I have info boxes at the top of the screen giving me different widget info, what I wanted is one of these info boxes to give me a total of how many widgets have been in stock for 45 days +
I am using this code for other sections of the site but I hate working with days/dates and simply cannot get my head round where and how I put the count in for the ones over 45 days
$widget45days = $db->query("SELECT id FROM widgettracker WHERE widgetstatus='Widgets for Sale'");
$widget45dayscounted = $widget45days->rowCount();
Advertisement
Answer
The query should look like this:
SELECT *
FROM widgettracker
WHERE dadded < NOW() - INTERVAL 45 DAY;