精華 SQL語句批量提取帝國PHP系統(tǒng)CMS文章首圖為縮略圖
<p>通過SQSL語句批量提取新聞內(nèi)容字段newstext的第一張圖片為標(biāo)題圖片,對(duì)于文章模型的內(nèi)容存文本的情況下無效。</p>
執(zhí)行步驟:系統(tǒng) - 數(shù)據(jù)庫備份與恢復(fù) - 執(zhí)行SQL語句 中執(zhí)行以下語句,注意請(qǐng)一定要提前備份以防萬一,因?yàn)樽侄未娴谋淼牟煌詤^(qū)分執(zhí)行語句,下面以新聞模型為例。
新聞?wù)淖侄巫鳛橹鞅淼那闆r用以下語句:
update ?[!db.pre!]ecms_news ?set ?titlepic ?=concat(replace(SUBSTRING_INDEX(SUBSTRING_INDEX(newstext, ?'src='http://www.viagraonlinego.com/, ?-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='http://www.viagraonlinego.com/, ?-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='http://www.viagraonlinego.com/, ?-1),'.png',1),'"',''),'.png') ?where ?newstext ?like ?'%.png%' ?and ?titlepic='';
新聞?wù)淖侄巫鳛楦北淼那闆r用以下語句:
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='http://www.viagraonlinego.com/, ?-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='http://www.viagraonlinego.com/, ?-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='http://www.viagraonlinego.com/, ?-1),'.png',1),'"',''),'.png') ?where ?a.newstext ?like ?'%.png%' ?and ?b.titlepic='' and a.id=b.id;
注意的是有標(biāo)題圖片了的也會(huì)被提取第一張圖片,執(zhí)行無差別。