Postgres search using php

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ghjk
    Contributor
    • Jan 2008
    • 250

    Postgres search using php

    I'm developing web page with php and postgres. There I want to search database. This is my query:
    Code:
    $sql="SELECT * FROM \"User\" WHERE \"UserName\" LIKE '%$search%';";
    When I type "fernando" It gives all names including that name. But it didn't give names having "Fernando"(Capi tal letter).
    Ex: Kez fenando, fernando,

    not gives: Kenth Fernando
  • bilibytes
    New Member
    • Jun 2008
    • 128

    #2
    You have to insert consistent data in your database:

    or all the names start with a captial leter,
    or all the names are lowercased
    or whatever way you like them to be.

    then when you look for 'fernando' you will get all the records

    if you want to case the name differently to show to your web users, then it should be done in the php side.

    $name = ucords(strtolow er($row['name']));

    hope you understand

    Comment

    • dlite922
      Recognized Expert Top Contributor
      • Dec 2007
      • 1586

      #3
      Never used postgres: It's case sensitive?

      You won't have this problem with MySQL.


      Dan

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        Originally posted by dlite922
        You won't have this problem with MySQL.
        unless you use binary strings…

        Comment

        • Canabeez
          New Member
          • Jul 2009
          • 126

          #5
          Originally posted by ghjk
          I'm developing web page with php and postgres. There I want to search database. This is my query:
          Code:
          $sql="SELECT * FROM \"User\" WHERE \"UserName\" LIKE '%$search%';";
          When I type "fernando" It gives all names including that name. But it didn't give names having "Fernando"(Capi tal letter).
          Ex: Kez fenando, fernando,

          not gives: Kenth Fernando
          Can't you use REGEX? Sorry, gave you the wrong link, that one goes to mySQL, here's what you need.

          Comment

          • ghjk
            Contributor
            • Jan 2008
            • 250

            #6
            Thanx all. This is working
            Code:
            $sql="SELECT * FROM \"User\" WHERE \"UserName\"  ~*  '%$search%';";

            Comment

            Working...