码迷,mamicode.com
首页 > 其他好文 > 详细

批量恢复zencart产品表master_categories_id=0的产品

时间:2014-08-29 14:35:27      阅读:169      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   color   io   ar   for   数据   art   

批量恢复zencart产品表所属分类master_categories_id为0的产品

将下面代码保存为master_categories_id.php,上传到网站根目录运行即可,操作前先备份数据库

<?php
header("content-Type: text/html; charset=utf-8"); 
/***
批量恢复zencart产品表master_categories_id0的产品
***/
require(‘includes/application_top.php‘);
echo ‘正在处理...‘;
$products_query = "select products_id from " . TABLE_PRODUCTS . " where master_categories_id = ‘0‘ order by products_id";
$products = $db->Execute($products_query);
$id_array = array();
while(!$products->EOF){
    $id_array[] = $products->fields[‘products_id‘];
    $products->MoveNext();     
}

foreach($id_array as $val){
    $categories_id = $db->Execute("select categories_id from " . TABLE_PRODUCTS_TO_CATEGORIES . " where products_id = ‘".(int)$val."‘ limit 0,1");
    if($categories_id->fields[‘categories_id‘]){        
        $products=$db->Execute("update " . TABLE_PRODUCTS . " set master_categories_id = ‘" .$categories_id->fields[‘categories_id‘]. "‘ where products_id = " . (int)$val);
    }
}
echo ‘OK!处理完毕‘;
require(DIR_WS_INCLUDES . ‘application_bottom.php‘);
?>

 

批量恢复zencart产品表master_categories_id=0的产品

标签:des   style   blog   color   io   ar   for   数据   art   

原文地址:http://www.cnblogs.com/afish/p/3944844.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!