第一天搞php+mysql,想写一个查找1000条记录的 文本字段(1000个字符),找出包含A字串,B字串,C字串的记录,对应替换沉D,E,F字符串,写回对应记录,并保存到数据库.
/* 连接选择数据库 */
$link = mysql_connect("*.*.*.*", "******", "******") or die("Could not connect
");
mysql_select_db("hdm0990625_db") or die("Could not select database
");
/* 执行 SQL 查询 */
$query = "SELECT goods_id,intro FROM sdb_goods where (intro like '%http://misc.360buyimg.com/product/skin/2013/i/20130604A.png%') or (intro like '%天猫%') or (intro like '%淘宝%') or (intro like '%%E5%A4%A9%E7%8C%A%') or (intro like '%%E6%B7%98%E5%AE%9D%') or (intro like '%%BA%AC%E4%B8%9C%')";
$result = mysql_query($query) or die("Query failed");
$i=0;
$txt="";
while($row = mysql_fetch_array($result))
{
//print $row['goods_id'];
$txt=str_replace("http://misc.360buyimg.com/product/skin/2013/i/20130604A.png","/themes/newjd/images/cndqc.png",$row['intro']);
$txt=str_replace("天猫","商城",$txt);
$txt=str_replace("淘宝","商城",$txt);
$txt=str_replace("京东","商城",$txt);
$txt=str_replace("%E5%A4%A9%E7%8C%A","商城",$txt);
$txt=str_replace("%E6%B7%98%E5%AE%9D","商城",$txt);
$txt=str_replace("%BA%AC%E4%B8%9C","商城",$txt);
mysql_query("UPDATE sdb_goods SET intro='".$txt."' WHERE goods_id = '".$row['goods_id']."'");
//print $txt;
//print "
";
$txt="";
$i++;
}
print "
";
print $i;
/* 释放资源 */
mysql_free_result($result);
/* 断开连接 */
mysql_close($link);
?>
程序有问题?
mysql_query("UPDATE sdb_goods SET intro='$txt' WHERE goods_id = '$row['goods_id']'");
mysql_query("UPDATE sdb_goods SET intro='".$txt."' WHERE goods_id = '".$row['goods_id']."'");
这2句哪句是对的?
回复讨论(解决方案)
$query = "SELECT goods_id,intro FROM sdb_goods where (intro like '%http://misc.360buyimg.com/product/skin/2013/i/20130604A.png%') or (intro like '%天猫%') or (intro like '%淘宝%') or (intro like '%%E5%A4%A9%E7%8C%A%') or (intro like '%%E6%B7%98%E5%AE%9D%') or (intro like '%%BA%AC%E4%B8%9C%')";
如果开头是
查询少了2个
天猫 淘宝 查询不出来
怎么处理?
再加20分,在线等,完成马上结贴
有没有人?????????