我有一个列表,显示从公司开始的所有订单。这个php脚本如下所示:
<?php
if (isset($HTTP_GET_VARS['cID'])) {
$cID = tep_db_prepare_input($HTTP_GET_VARS['cID']);
$orders_query_raw = "select o.orders_id, o.customers_id, o.customers_name, o.customers_id, o.payment_method, o.date_purchased, o.franchise_id, o.last_modified, o.date_allocated, o.currency, o.currency_value, s.orders_status_name, ot.text as order_total from " . TABLE_ORDERS . " o left join " . TABLE_ORDERS_TOTAL . " ot on (o.orders_id = ot.orders_id), " . TABLE_ORDERS_STATUS . " s where o.customers_id = '" . (int)$cID . "' and o.orders_status = s.orders_status_id and s.language_id = '" . (int)$languages_id . "' and ot.class = 'ot_total' order by orders_id DESC where date_purchased = CONCAT(date(date_sub(now(), interval 1 day)), '17:00:00')";
} elseif (isset($HTTP_GET_VARS['status']) && is_numeric($HTTP_GET_VARS['status']) && ($HTTP_GET_VARS['status'] > 0)) {
$status = tep_db_prepare_input($HTTP_GET_VARS['status']);
$orders_query_raw = "select o.orders_id, o.customers_id, o.customers_name, o.payment_method, o.franchise_id,o.date_purchased, o.last_modified, o.currency, o.currency_value, o.date_allocated, s.orders_status_name, ot.text as order_total from " . TABLE_ORDERS . " o left join " . TABLE_ORDERS_TOTAL . " ot on (o.orders_id = ot.orders_id), " . TABLE_ORDERS_STATUS . " s where o.orders_status = s.orders_status_id and s.language_id = '" . (int)$languages_id . "' and s.orders_status_id = '" . (int)$status . "' and ot.class = 'ot_total' order by o.orders_id DESC where date_purchased = CONCAT(date(date_sub(now(), interval 1 day)), '17:00:00') ";
} else {
$orders_query_raw = "select o.orders_id, o.customers_id, o.customers_name, o.payment_method, o.date_purchased, o.franchise_id, o.last_modified, o.date_allocated, o.currency, o.currency_value, s.orders_status_name, ot.text as order_total from " . TABLE_ORDERS . " o left join " . TABLE_ORDERS_TOTAL . " ot on (o.orders_id = ot.orders_id), " . TABLE_ORDERS_STATUS . " s where o.orders_status = s.orders_status_id and s.language_id = '" . (int)$languages_id . "' and ot.class = 'ot_total' order by o.orders_id DESC where date_purchased = CONCAT(date(date_sub(now(), interval 1 day)), '17:00:00')";
}
$orders_split = new splitPageResults($HTTP_GET_VARS['page'], MAX_DISPLAY_SEARCH_RESULTS, $orders_query_raw, $orders_query_numrows);
$orders_query = tep_db_query($orders_query_raw);
while ($orders = tep_db_fetch_array($orders_query)) {
if ((!isset($HTTP_GET_VARS['oID']) || (isset($HTTP_GET_VARS['oID']) && ($HTTP_GET_VARS['oID'] == $orders['orders_id']))) && !isset($oInfo)) {
$oInfo = new objectInfo($orders);
}
if (isset($oInfo) && is_object($oInfo) && ($orders['orders_id'] == $oInfo->orders_id)) {
echo ' <tr id="defaultSelected" class="dataTableRowSelected" onmouseover="rowOverEffect(this)" onmouseout="rowOutEffect(this)" onclick="document.location.href=\'' . tep_href_link(FILENAME_ORDERS, tep_get_all_get_params(array('oID', 'action')) . 'oID=' . $oInfo->orders_id . '&action=edit') . '\'">' . "\n";
} else {
echo ' <tr class="dataTableRow" onmouseover="rowOverEffect(this)" onmouseout="rowOutEffect(this)" onclick="document.location.href=\'' . tep_href_link(FILENAME_ORDERS, tep_get_all_get_params(array('oID')) . 'oID=' . $orders['orders_id']) . '\'">' . "\n";
}
?>
<td class="dataTableContent"><?php echo '<a href="' . tep_href_link(FILENAME_ORDERS, tep_get_all_get_params(array('oID', 'action')) . 'oID=' . $orders['orders_id'] . '&action=edit') . '">' . tep_image(DIR_WS_ICONS . 'preview.gif', ICON_PREVIEW) . '</a> ' . $orders['customers_name']; ?></td>
<td class="dataTableContent" align="right"><?php echo strip_tags($orders['order_total']); ?></td>
<td class="dataTableContent" align="center"><?php echo tep_datetime_short($orders['date_purchased']); ?></td>
<td class="dataTableContent" align="right"><?php echo $orders['orders_status_name'].' '.'['.$orders ['franchise_id'].']'; ?></td>
<td class="dataTableContent" align="right"><?php if (isset($oInfo) && is_object($oInfo) && ($orders['orders_id'] == $oInfo->orders_id)) { echo tep_image(DIR_WS_IMAGES . 'icon_arrow_right.gif', ''); } else { echo '<a href="' . tep_href_link(FILENAME_ORDERS, tep_get_all_get_params(array('oID')) . 'oID=' . $orders['orders_id']) . '">' . tep_image(DIR_WS_IMAGES . 'icon_info.gif', IMAGE_ICON_INFO) . '</a>'; } ?> </td>
</tr>
<?php
}
?>
我尝试使用where date_purchased = CONCAT(date(date_sub(now(), interval 1 day)), '17:00:00')
仅显示当天17:00:00到当天17:00:00之后的订单。上面的代码显示错误。有关修理的任何帮助吗?
答案 0 :(得分:2)
检查变量TABLE_ORDERS
的值,它必须是o.date_purchased
答案 1 :(得分:1)
以下是您的查询的一部分:
where o.orders_status = s.orders_status_id and s.language_id = '" . (int)$languages_id . "' and ot.class = 'ot_total' order by o.orders_id DESC where date_purchased = CONCAT(date(date_sub(now(), interval 1 day)), '17:00:00')";
订购不正确。 ORDER BY
总是最后一个,此外你不能有多个“WHERE
”语句,在第一个语句之后它会变为AND / OR,具体取决于你的逻辑。
将这两个并排比较,WHERE
更改为AND
,ORDER BY
放在最后。
where o.orders_status = s.orders_status_id and s.language_id = '" . (int)$languages_id . "' and ot.class = 'ot_total' AND date_purchased = CONCAT(date(date_sub(now(), interval 1 day)), '17:00:00') order by o.orders_id DESC ";
干杯,
韦斯