网络营销电子商务研究中心  
How to buy the best prescription safety glasses in Canada? Let's study!
Go Back   网络营销电子商务研究中心 > 服务器与数据库 > 服务器环境搭建
User Name
Password
 
FAQ Members List Calendar Cheap Glasses

服务器环境搭建 Windows,Linux,IIS,Apache等服务器配置、安全维护以及PHP和MYSQL运行环境讨论。

Reply
 
Thread Tools Display Modes
  #1   IP: 114.238.135.134
Old 2011-04-07, 06:47 AM
topvip topvip is offline
超级版主
 
Join Date: 2006-01-04
Posts: 1206
topvip 正向着好的方向发展
Default 使用sql语句,替换MySQL指定字段中的字符串

然用了很多次的CMS,对于数据库的操作也不算少,但从来没有执行过sql语句,在我的印象里,那应该是一种很高深的内容,像我等菜鸟只能是玩玩html就可以了。

但是问题终于还是来了。从网上采集了近两万数据,用了近一周的时间才陆续把这些内容传到数据库里,突然发现每条数据都有些问题。在网页编辑页面内什么都看不出来,但是生成网页后整个页面布局严重变形,这在以前是从来没有出现过的。仔细查看源代码,原来在每条数据中都多了一条没用的代码,虽然我感觉没用,但网页解释起来却很用,生生把页面撑破了。

其实刚采集的时候已经注意到,就是没有当回事,现在可倒好,两万条数据可怎么改?

没办法,只好学习一点sql语言直接对数据库下手吧。

在网上搜索了很多,语句大都一样:
update 表名 set 字段名=replace(字段名,'原来的内容','替换后的内容')

update wp_posts set post_content=replace(post_content,'glasses','<a href=http://www.cheapglasses123.com>cheap glasses</a>')

试着操作了下,没想到不到一分钟就提示完成,再看内容已经完好了。

俗话说,隔行如隔山,学习也是如此,不接触不知道,原来sql语法就样强大!虽然我老了,有时间还真得学学,不能做到知其所然,起码能用一句两句解决实际问题就行了。
Reply With Quote
  #2   IP: 49.87.1.20
Old 2011-04-24, 10:10 PM
topvip topvip is offline
超级版主
 
Join Date: 2006-01-04
Posts: 1206
topvip 正向着好的方向发展
Default

将数据库中的glasses更新成<a href=http://www.cheapglasses123.com>cheap glasses</a>
update wp_posts set post_content=replace(post_content,'glasses','<a href=http://www.cheapglasses123.com>cheap glasses</a>')


将数据库中的http://www.spectaclesexpert.com更新成http://www.glassespeople.com
update wp_posts set post_content=replace(post_content,'http://www.spectaclesexpert.com','http://www.glassespeople.com')
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is On
HTML code is Off

Forum Jump

Prescription-glasses.com offers prescription glasses online at discount prices.
All times are GMT +8. The time now is 07:29 AM.


Powered by vBulletin Version 3.8.7
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.