帝国CMS批量提取内容的第一张图片为标题图片的SQL语句是什么?

发布时间:2021-03-31作者:帝国建站网

通过SQSL语句批量提取新闻内容字段newstext的第一张图片为标题图片,对于文章模型的内容存文本的情况下无效。

执行步骤:系统 - 数据库备份与恢复 - 执行SQL语句 中执行以下语句,注意请一定要提前备份以防万一,因为字段存的表的不同所以区分执行语句,下面以新闻模型为例。

新闻正文字段作为主表的情况用以下语句:

update  [!db.pre!]ecms_news  set  titlepic  =concat(replace(SUBSTRING_INDEX(SUBSTRING_INDEX(newstext,  'src=',  -1),'.gif',1),'"',''),'.gif')  where  newstext  like  '%.gif%'  and  titlepic='';
update  [!db.pre!]ecms_news  set  titlepic  =concat(replace(SUBSTRING_INDEX(SUBSTRING_INDEX(newstext,  'src=',  -1),'.jpg',1),'"',''),'.gif')  where  newstext  like  '%.jpg%'  and  titlepic='';
update  [!db.pre!]ecms_news  set  titlepic  =concat(replace(SUBSTRING_INDEX(SUBSTRING_INDEX(newstext,  'src=',  -1),'.png',1),'"',''),'.png')  where  newstext  like  '%.png%'  and  titlepic='';

新闻正文字段作为副表的情况用以下语句:

update [!db.pre!]ecms_news_data_1 a, [!db.pre!]ecms_news b set b.titlepic=concat(replace(SUBSTRING_INDEX(SUBSTRING_INDEX(a.newstext,  'src=',  -1),'.gif',1),'"',''),'.gif')  where  a.newstext  like  '%.gif%'  and  b.titlepic='' and a.id=b.id;
update [!db.pre!]ecms_news_data_1 a, [!db.pre!]ecms_news b set b.titlepic=concat(replace(SUBSTRING_INDEX(SUBSTRING_INDEX(a.newstext,  'src=',  -1),'.jpg',1),'"',''),'.jpg')  where  a.newstext  like  '%.jpg%'  and  b.titlepic='' and a.id=b.id;
update [!db.pre!]ecms_news_data_1 a, [!db.pre!]ecms_news b set b.titlepic=concat(replace(SUBSTRING_INDEX(SUBSTRING_INDEX(a.newstext,  'src=',  -1),'.png',1),'"',''),'.png')  where  a.newstext  like  '%.png%'  and  b.titlepic='' and a.id=b.id;


注意的是有标题图片了的也会被提取第一张图片,执行无差别。

以上就是帝国CMS批量提取新闻内容的第一张图片为标题图片的SQL语句。

上一篇:帝国CMS灵动标签调用栏目名称,出现的却是栏目别名内容的解决方法!

下一篇:帝国cms TAGS功能介绍与管理