偶初来乍到,很感谢站长的回复!:)
我把代码翻来覆去的看了好久还是不得要领。站长能不能费心看看我的源代码呢?谢谢!
原文件中涉及到好几处有 select count(*) as total ,为节省精力计我贴出下面这一段最有可能出错的部分:select count(*) 在line 34:
[php]
case 'delete_classification_confirm':
if (isset($HTTP_POST_VARS['classification_id'])) {
$classification_id = tep_db_prepare_input($HTTP_POST_VARS['classification_id']);
$classification = tep_get_classification_tree($classification_id, '', '0', '', true);
$customers = array();
$customers_delete = array();
for ($i=0, $n=sizeof($classification); $i<$n; $i++) {
$customers_ids_query = tep_db_query("select customers_id from " . TABLE_CUSTOMERS_TO_CLASSIFICATION . " where classification_id = '" . (int)$classification[$i]['id'] . "'");
while ($customers_ids = tep_db_fetch_array($customers_ids_query)) {
$customers[$customers_ids['customers_id']]['classification'][] = $classification[$i]['id'];
}
}
reset($customers);
while (list($key, $value) = each($customers)) {
$classification_ids = '';
for ($i=0, $n=sizeof($value['classification']); $i<$n; $i++) {
$classification_ids .= "'" . (int)$value['classification'][$i] . "', ";
}
$classification_ids = substr($classification_ids, 0, -2);
$check_query = tep_db_query("select count(*) as total from " . TABLE_CUSTOMERS_TO_CLASSIFICATION . " where customers_id = '" . (int)$key . "' and classification_id not in (" . $classification_ids . ")");
$check = tep_db_fetch_array($check_query);
if ($check['total'] < '1') {
$customers_delete[$key] = $key;
}
}
// removing classification can be a lengthy process
tep_set_time_limit(0);
for ($i=0, $n=sizeof($classification); $i<$n; $i++) {
tep_remove_classification($classification[$i]['id']);
}
reset($customers_delete);
while (list($key) = each($customer_delete)) {
tep_remove_customer($key);
}
}
if (USE_CACHE == 'true') {
tep_reset_cache_block('classification');
}
tep_redirect(tep_href_link(FILENAME_CUSTOMERS, 'ccPath=' . $ccPath));
break;
其中tep_db_prepare_input、tep_get_classification_tree、tep_db_query、tep_db_fetch_array、tep_remove_classification、 tep_remove_customer、tep_reset_cache_block、tep_redirect 是自定义函数,TABLE_CUSTOMERS_TO_CLASSIFICATION 是一自建表,分别定义如下:
function tep_db_prepare_input($string) {
if (is_string($string)) {
return trim(stripslashes($string));
} elseif (is_array($string)) {
reset($string);
while (list($key, $value) = each($string)) {
$string[$key] = tep_db_prepare_input($value);
}
return $string;
} else {
return $string;
}
}
function tep_get_classification_tree($parent_id = '0', $spacing = '', $exclude = '', $classification_tree_array = '', $include_itself = false) {
global $languages_id;
if (!is_array($classification_tree_array)) $classification_tree_array = array();
if ( (sizeof($classification_tree_array) < 1) && ($exclude != '0') ) $classification_tree_array[] = array('id' => '0', 'text' => TEXT_TOP);
if ($include_itself) {
$classification_query = tep_db_query("select cd.classification_name from " . TABLE_CUSTOMERS_CLASSIFICATION_DESCRIPTION . " cd where cd.language_id = '" . (int)$languages_id . "' and cd.classification_id = '" . (int)$parent_id . "'");
$classification = tep_db_fetch_array($classification_query);
$classification_tree_array[] = array('id' => $parent_id, 'text' => $classification['classification_name']);
}
$classification_query = tep_db_query("select c.classification_id, cd.classification_name, c.parent_id from " . TABLE_CUSTOMERS_CLASSIFICATION . " c, " . TABLE_CUSTOMERS_CLASSIFICATION_DESCRIPTION . " cd where c.classification_id = cd.classification_id and cd.language_id = '" . (int)$languages_id . "' and c.parent_id = '" . (int)$parent_id . "' order by c.sort_order, cd.classification_name");
while ($classification = tep_db_fetch_array($classification_query)) {
if ($exclude != $classification['classification_id']) $classification_tree_array[] = array('id' => $classification['classification_id'], 'text' => $spacing . $classification['classification_name']);
$classification_tree_array = tep_get_classification_tree($classification['classification_id'], $spacing . ' ', $exclude, $classification_tree_array);
}
return $classification_tree_array;
}
function tep_db_query($query, $link = 'db_link') {
global $$link, $logger;
if (defined('STORE_DB_TRANSACTIONS') && (STORE_DB_TRANSACTIONS == 'true')) {
if (!is_object($logger)) $logger = new logger;
$logger->write($query, 'QUERY');
}
$result = mysql_query($query, $$link) or tep_db_error($query, mysql_errno(), mysql_error());
if (defined('STORE_DB_TRANSACTIONS') && (STORE_DB_TRANSACTIONS == 'true')) {
if (mysql_error()) $logger->write(mysql_error(), 'ERROR');
}
return $result;
}
function tep_db_fetch_array($db_query) {
return mysql_fetch_array($db_query, MYSQL_ASSOC);
}
function tep_remove_classification($classification_id) {
$classification_image_query = tep_db_query("select classification_image from " . TABLE_CUSTOMERS_CLASSIFICATION . " where classification_id = '" . (int)$classification_id . "'");
$classification_image = tep_db_fetch_array($classification_image_query);
$duplicate_image_query = tep_db_query("select count(*) as total from " . TABLE_CUSTOMERS_CLASSIFICATION . " where classification_image = '" . tep_db_input($classification_image['classification_image']) . "'");
$duplicate_image = tep_db_fetch_array($duplicate_image_query);
if ($duplicate_image['total'] < 2) {
if (file_exists(DIR_FS_CATALOG_IMAGES . $classification_image['classification_image'])) {
@unlink(DIR_FS_CATALOG_IMAGES . $classification_image['classification_image']);
}
}
tep_db_query("delete from " . TABLE_CUSTOMERS_CLASSIFICATION . " where classification_id = '" . (int)$classification_id . "'");
tep_db_query("delete from " . TABLE_CUSTOMERS_CLASSIFICATION_DESCRIPTION . " where classification_id = '" . (int)$classification_id . "'");
tep_db_query("delete from " . TABLE_CUSTOMERS_TO_CLASSIFICATION . " where classification_id = '" . (int)$classification_id . "'");
if (USE_CACHE == 'true') {
tep_reset_cache_block('classification');
}
}
function tep_remove_customer($customers_id) {
tep_db_query("delete from " . TABLE_CUSTOMERS . " where customers_id = '" . (int)$customers_id . "'");
tep_db_query("delete from " . TABLE_CUSTOMERS_INFO . " where customers_info_id = '" . (int)$customers_id . "'");
tep_db_query("delete from " . TABLE_ADDRESS_BOOK . " where customers_id = '" . (int)$customers_id . "'");
tep_db_query("delete from " . TABLE_CUSTOMERS_TO_CLASSIFICATION . " where customers_id = '" . (int)$customers_id . "'");
tep_db_query("delete from " . TABLE_ORDERS . " where customers_id = '" . (int)$customers_id . "'");
tep_db_query("delete from " . TABLE_REVIEWS . " where customers_id = '" . (int)$customers . "'");
tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET . " where customers_id = '" . (int)$customers . "'");
tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " where customers_id = '" . (int)$customers . "'");
tep_db_query("delete from " . TABLE_WHOS_ONLINE . " where customer_id = '" . (int)$customers_id . "'");
$customers_reviews_query = tep_db_query("select reviews_id from " . TABLE_REVIEWS . " where customers_id = '" . (int)$customers_id . "'");
while ($customers_reviews = tep_db_fetch_array($product_reviews_query)) {
tep_db_query("delete from " . TABLE_REVIEWS_DESCRIPTION . " where reviews_id = '" . (int)$customers_reviews['reviews_id'] . "'");
}
tep_db_query("delete from " . TABLE_REVIEWS . " where customers_id = '" . (int)$customers_id . "'");
if (USE_CACHE == 'true') {
tep_reset_cache_block('classifications');
}
}
function tep_reset_cache_block($cache_block) {
global $cache_blocks;
for ($i=0, $n=sizeof($cache_blocks); $i<$n; $i++) {
if ($cache_blocks[$i]['code'] == $cache_block) {
if ($cache_blocks[$i]['multiple']) {
if ($dir = @opendir(DIR_FS_CACHE)) {
while ($cache_file = readdir($dir)) {
$cached_file = $cache_blocks[$i]['file'];
$languages = tep_get_languages();
for ($j=0, $k=sizeof($languages); $j<$k; $j++) {
$cached_file_unlink = ereg_replace('-language', '-' . $languages[$j]['directory'], $cached_file);
if (ereg('^' . $cached_file_unlink, $cache_file)) {
@unlink(DIR_FS_CACHE . $cache_file);
}
}
}
closedir($dir);
}
} else {
$cached_file = $cache_blocks[$i]['file'];
$languages = tep_get_languages();
for ($i=0, $n=sizeof($languages); $i<$n; $i++) {
$cached_file = ereg_replace('-language', '-' . $languages[$i]['directory'], $cached_file);
@unlink(DIR_FS_CACHE . $cached_file);
}
}
break;
}
}
}
[/php]
|
|