dongxi5423 2012-07-27 00:43
浏览 92
已采纳

处理mysql中的特殊字符

I have 2 mysql tables property and building. In property table i have a field called unitnumber the value in this field is like 1a, 2b etc.. In the building table i have a field called address which is in PHP's urlencoded format. The value will be something like 26+Dovedale+Place%2C+Parnell

Now i want to implement a search function so that when user types 1a, 26 Dovedale I need to pull up the result from the database.

Implemented So Far:

    $keyword = preg_replace('/[^a-zA-Z0-9-]/', '', $_REQUEST['keyword']);
    $keyword = str_replace(" ", "-", $keyword);
    $a->rqNotEmpty('keyword', $keyword);

    $query = "SELECT * FROM `buildings` b left join properties p on p.buildingId=b.id 
      WHERE concat(p.floor,p.number,b.address) LIKE '%".$keyword."%'
      or concat(p.number,p.floor,b.address)  LIKE '%".$keyword."'";

But now the problem is when i prepare the $keyword variable i will get something like 1a26Dovedale and in database after CONCAT the value will be somethign like 1a26+Dovedale+Place%2C+Parnell. I cant urlencode the $keyword because the database is not in standardized form. The database my have 2 spaces between the address. So is there a way to urldecode mysql string ?? I am dealing with nearly 4 million records here!!

  • 写回答

1条回答 默认 最新

  • douya2006 2012-07-27 02:32
    关注

    You could try installing a MySQL UDF (User Defined Function) to provide the urlencode() and urldecode() functions within MySQL. Here's the link: http://freecode.com/projects/libmysqludf

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥50 我撰写的python爬虫爬不了 要爬的网址有反爬机制
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥120 计算机网络的新校区组网设计
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等