dongxiangshen7916 2014-03-22 06:11
浏览 316
已采纳

删除MySQL字段值中字符串值的开头或结尾处的空格[复制]

This question already has an answer here:

I have a PHP file to compare strings from a MySQL table and from a URL parameter.

I have detected a problem, some of the MySQL strings have blank spaces at the beginning and/or at the end of the string, and I don't know how to manage it, then sometimes the query is empty because of the blank spaces. In my case, the source string is part of a URL parameter, $id, and the string to be compared is the string value of the field titulo

$id = $_GET['id'];

$arr = array();

$rs = mysql_query("SELECT * FROM tbcoordenadas where titulo='$id'");
while ($obj = mysql_fetch_assoc($rs)){
$arr[] = $obj['procedencia'];
}
echo json_encode($arr);

I would appreciate any help to solve this issue.

EXPLANATION CONSIDERING THIS IS NOT A DUPLICATE QUESTION.

As you all may see, the question supposed to be duplicated is not considering in any answer what I am asking in my question. My question is not about removing white spaces from a string, it is about removing white spaces of a MySQL field value.

</div>
  • 写回答

2条回答 默认 最新

  • dongshi8359 2014-03-22 06:13
    关注

    You can use

    $rs = mysql_query("SELECT * FROM tbcoordenadas where trim(titulo)='$id'");
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 路易威登官网 里边的参数逆向
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?
  • ¥50 需求一个up主付费课程
  • ¥20 模型在y分布之外的数据上预测能力不好如何解决
  • ¥15 processing提取音乐节奏
  • ¥15 gg加速器加速游戏时,提示不是x86架构
  • ¥15 python按要求编写程序
  • ¥15 Python输入字符串转化为列表排序具体见图,严格按照输入