用户名:  密码:    
中药方大全小图标
关键字:  
您当前的位置:首页 > 其他 > 网站日记

帝国cms批量添加tags的函数改良

提示: 阅读权限:公开  来源:jiuhecai  作者:jiuhecai

前文见---帝国cms7.2后台信息列表页批量添加tags

 http://www.zhongyf.com/qita/rj/2015-02-19/91911.html

对于其中的主要函数,jiuhecai做了改进,使得逻辑清晰,执行效率更高。

尤其是其中针对mysql的操作jiuhecai使用了比较少用但是高效的mysql函数,值得收藏学习。

  1. function eInsertTags2($tags,$classid,$idr,$newstime){   
  2.     global $empire,$dbtbpre,$class_r; 
  3. //参数检查
  4.     $tagname = RepPostVar($tags); 
  5.     if(!trim($tagname))printerror("TAGS信息不能为空", "", 1, 0, 1);
  6. $tag = explode(",", $tagname);   
  7.     if(count($tag)>1)printerror("只能添加一个TAGS词", "", 1, 0, 1);  
  8.     $count = count($idr); //统计ID数量   
  9.     if(empty($count))printerror("未选择信息ID", "", 1, 0, 1);
  10.     
  11.     $classid=(int)$classid;   
  12.     $mid=(int)$class_r[$classid][modid]; //获取模型id
  13.     $tbname=$class_r[$classid][tbname];//获取表名
  14.     //获取tagid
  15.     $tagid=(int)$empire->gettotal("select tagid as total from {$dbtbpre}enewstags 
  16.                                     where tagname='$tagname'");
  17.     if($tagid==0){ //新增tag
  18.         $empire->query("insert into {$dbtbpre}enewstags(tagname,num,isgood,cid) 
  19.                                                 values('$tagname',1,0,0);");   
  20.         $tagid=$empire->lastid();     
  21.     }else{ //已经存在的tag,过滤掉已经添加过的
  22.         $ids=join(',',$idr);
  23.         $allids=$empire->gettotal("select group_concat(id) as total 
  24.                                     from {$dbtbpre}enewstagsdata 
  25.                                     where
  26.                                         tagid='$tagid'and id in($ids) and mid='$mid' ");
  27.         $allidr=explode(',',$allids);
  28.         $idr=array_diff($idr,$allidr);
  29.         if(empty($idr))printerror("已经有了,无需重复添加", "", 1, 0, 1);
  30.     }
  31.     //开始正经干活
  32.     foreach($idr as $id){
  33.         //获得副表名称
  34.          $jhcr = $empire->fetch1("select classid,stb,newstime from {$dbtbpre}ecms_".$tbname.
  35.                             where id='$id' limit 1");
  36.         //更新副表
  37.         $ftbname=$dbtbpre."ecms_".$tbname."_data_".$jhcr['stb'];
  38.         $empire->query("update $ftbname set 
  39.                         infotags=trim(BOTH ',' from concat(infotags,',','$tagname')) 
  40.                         where id='$id'");   
  41.         //更新tags数据表
  42.          $empire->query("insert into {$dbtbpre}enewstagsdata(tagid,classid,id,newstime,mid)
  43.                             values('$tagid','$jhcr[classid]','$id','$jhcr[newstime]','$mid')"); 
  44.     }
  45.     //更新tags主表
  46.     $empire->query("update {$dbtbpre}enewstags set num=num+".count($idr)."
  47.                      where tagid='$tagid'");   
  48.     printerror("批量添加TAGS成功", "", 1, 0, 1);   
  49. }


tags: 帝国cms tags 批量 帝国
返回顶部
推荐资讯
视频:田纪钧讲关节不痛的秘密、膝关节拉筋法
视频:田纪钧讲关节不
白露到了,你还好吗?
白露到了,你还好吗?
尿疗与断食
尿疗与断食
给风疹反复发作女孩的药方(组图)
给风疹反复发作女孩的
相关文章
栏目更新
栏目热门
  1. libreoffice7的命令大全
  2. 帝国cms代码片段备忘录
  3. 帝国cms插件之标题生成标题图片
  4. 帝国cms插件安装模板
  5. 帝国cms全站搜索的分页格式如何修改-流程
  6. 帝国cms中点卡怎么可以直接用来网站的登录
  7. 帝国cms插件之迅搜
  8. php代码判断是不是微信内部浏览器
  9. useragent两千条,爬虫专用
  10. 帝国cms7.2函数大全