毎月このクエリを実行するためのヘルプを探しています。
$params = array(&$_POST['query']);
$SQL1 = "SELECT SUM(Income) AS OrderTotal
FROM SalesDB
WHERE
SalesDB.[Posting Date] <= '2013-01-01' AND
SalesDB.[Posting Date] >= '2013-01-31'";
$options = array("Scrollable" => SQLSRV_CURSOR_KEYSET);
$getProducts1 = sqlsrv_query($conn, $SQL1, $params, $options);
if ($getProducts1 === false)
die( var_dump(sqlsrv_errors()) );
while ($row = sqlsrv_fetch_array( $getProducts1, SQLSRV_FETCH_ASSOC))
{
$row['OrderTotal'];
}
このようにして、1月の総収入を取得します。ループを実行する方法はありますか?それで、今年の毎月のクエリを実行しますか?
だから私はこの愚かな方法でそれをする必要はありません:
$params = array(&$_POST['query']);
$SQL1 = "SELECT SUM(Income) AS OrderTotal
FROM SalesDB
WHERE
SalesDB.[Posting Date] <= '2013-01-01' AND
SalesDB.[Posting Date] >= '2013-01-31'";
$options = array("Scrollable" => SQLSRV_CURSOR_KEYSET);
$getProducts1 = sqlsrv_query($conn, $SQL1, $params, $options);
if ($getProducts1 === false)
die( var_dump(sqlsrv_errors()) );
$SQL2 = "SELECT SUM(Income) AS OrderTotal
FROM SalesDB
WHERE
SalesDB.[Posting Date] <= '2013-02-01' AND
SalesDB.[Posting Date] >= '2013-02-28'";
$options = array("Scrollable" => SQLSRV_CURSOR_KEYSET);
$getProducts2 = sqlsrv_query($conn, $SQL2, $params, $options);
if ($getProducts2 === false)
die( var_dump(sqlsrv_errors()) );
while ($row1 = sqlsrv_fetch_array( $getProducts1, SQLSRV_FETCH_ASSOC) AND $row2 = sqlsrv_fetch_array( $getProducts2, SQLSRV_FETCH_ASSOC))
{
echo $row1['OrderTotal'];
echo $row2['OrderTotal'];
}