PHP
我在这里有一个问题。我正在使用以下查询。我正在使用循环运行此查询?
如何在没有循环的情况下运行此查询?
我不想在foreach中运行查询?我怎么能这样做?
我使用正确的方法来运行此查询吗?
加载需要时间。是否有任何优化来实现这一目标?
我需要执行多个查询才能一次运行它们吗?
<?php
$year = "2016";
$start = new DateTime($year.'-01-01');
$start->modify('first day of this month');
$end = new DateTime($year.'-12-31');
$end->modify('first day of next month');
$interval = DateInterval::createFromDateString('1 month');
$period = new DatePeriod($start, $interval, $end);
foreach ($period as $dt) {
$calcstart_date = $dt->format("Y-m-d").' 00:00:00';
$calcend_date = $dt->format("Y-m-t").' 11:59:00';
$month_name = $dt->format('M');
$test_submitted_query = db_query("
SELECT requester_id, email, username, is_dashboard_user, SUBMITTED_ON
FROM testing_a, aspusers a
WHERE requester_id=a.user_id
AND AD_MAIL_ATTRIBUTE IS NOT NULL
AND IS_DASHBOARD_USER = 'y'
AND SUBMITTED_ON >= timestamp '$calcstart_date'
AND SUBMITTED_ON <= timestamp '$calcend_date'
");
}
?>
答案 0 :(得分:2)
php部分不是nessesary,你可以使用mysql的date and time functions。
实施例
# The default backend; one of GTK GTKAgg GTKCairo GTK3Agg GTK3Cairo
# MacOSX Qt4Agg Qt5Agg TkAgg WX WXAgg Agg Cairo GDK PS PDF SVG
# Template.
# You can also deploy your own backend outside of matplotlib by
# referring to the module name (which must be in the PYTHONPATH) as
# 'module://my_backend'.
backend : qt5agg
你应该得到12行的结果