简体   繁体   English

Postgresql小写来比较数据

[英]Postgresql lowercase to compare data

I want to get the contents from a row in the Postgresql database and compare the lowercase version of it to a lowercase version of a user input to check if it exists in the database. 我想从Postgresql数据库的行中获取内容,并将其小写版本与用户输入的小写版本进行比较,以检查它是否存在于数据库中。

i tried: 我试过了:

"SELECT LOWER(name) FROM user_names WHERE name LIKE '%$search%' ORDER BY name ASC"

but that make query not working at all. 但这使得查询根本不起作用。

EDIT 编辑

I am trying to implement an autocomplete Jquery UI like here: http://jqueryui.com/demos/autocomplete/#remote for search box (for names) 我正在尝试实现一个自动完成Jquery UI,如下所示: http//jqueryui.com/demos/autocomplete/#remote for search box(for names)

using javascript and php. 使用javascript和php。

php code: php代码:

$search = ($_GET['term']);
       if (!$con)
        { die('Could not connect: ' . pg_last_error ());}

       else
        {

        $sql = "SELECT name FROM users_table WHERE name LIKE '%$search%' ORDER BY name ASC";
        $result = pg_query($sql);
        $json = '[';
        $first = true;
        while ($row = pg_fetch_array($result))
        {

        if (!$first) { $json .=  ','; } else { $first = false; }
        $json .= '{"value":"'.$row['name'].'"}';
    }
    $json .= ']';
    echo $json;

    exit();

    }

JavaScript code: JavaScript代码:

   $(document).ready(function()
    {
        $('#auto').autocomplete(
        {
            source: "./file.php",
            minLength: 3

        })

})

all above work great.. exactly like in Demo here: http://jqueryui.com/demos/autocomplete/#remote 以上所有工作都很棒..就像在这里的Demo: http//jqueryui.com/demos/autocomplete/#remote

my problem is that the names in database stored in Uppercase (eg LORI) and of course the user prefers to insert a lowercase in search box to search for name (eg lori). 我的问题是数据库中的名称存储在大写(例如LORI)中,当然用户更喜欢在搜索框中插入一个小写来搜索名称(例如lori)。 but since it stored in uppercase, i need to convert it. 但由于它以大写形式存储,我需要转换它。

i tried as your suggestion : 我试过你的建议:

$sql = "SELECT LOWER(name) FROM users_table WHERE name ILIKE '%$search%' ORDER BY name ASC";

then i got an empty drop down list! 然后我有一个空的下拉列表! pretty weird! 很奇怪!

thanks in advance. 提前致谢。

Google is your friend : 谷歌是你的朋友

SELECT LOWER(name) FROM user_names 
WHERE name ILIKE '%$search%' ORDER BY name ASC

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM