Shopex转到Ecshop后,商品相册图片数据重复的解决

2016-09-07 22:03 来源:www.chinab4c.com 作者:ecshop专家

 <?php

define('IN_ECS', true);

require(dirname(__FILE__) . '/includes/init.php');
 $q = $db->getAll("SELECT DISTINCT `img_url` FROM ". $ecs->table('goods_gallery'));
 foreach($q as $key => $val){
  $c = intval($db->getOne("SELECT count(0) FROM ". $ecs->table('goods_gallery') ." WHERE img_url='". $val['img_url'] ."'"));
  if($c>1){
   $c = intval($db->getOne("SELECT img_id FROM ". $ecs->table('goods_gallery') ." WHERE img_url='". $val['img_url'] ."' ORDER BY img_id LIMIT 0,1"));
   if($c>0){
    $sql = "DELETE FROM " . $ecs->table('goods_gallery') . " WHERE img_id <> ". $c ." and img_url='". $val['img_url'] ."'";
    $db->query($sql);
   }
  }
 }
?>

将以上内容保存成为一个php文件 运行即可

(责任编辑:chinab4c)