Received: from cooee.cybersydney.com.au (cooee.cybersydney.com.au [203.25.173.1]) by postgresql.org (8.11.3/8.11.1) with ESMTP id f360ww815716 for ; Thu, 5 Apr 2001 20:58:59 -0400 (EDT) (envelope-from csmith@squiz.net) Received: from area51.cybersydney.com.au (csmith@pc163.cybersydney.com.au [203.25.173.163] (may be forged)) by cooee.cybersydney.com.au (8.8.7/8.8.7) with SMTP id LAA16524; Fri, 6 Apr 2001 11:02:06 +1000 Content-Type: text/plain; charset="iso-8859-1" From: Chris Smith Organization: Squiz To: rickf , pgsql-php@postgresql.org Subject: Re: Wildcard queries via PHP4 Date: Fri, 6 Apr 2001 10:57:41 +1000 X-Mailer: KMail [version 1.2] References: <5.0.2.1.0.20010405200751.009ed470@127.0.0.1> In-Reply-To: <5.0.2.1.0.20010405200751.009ed470@127.0.0.1> MIME-Version: 1.0 Message-Id: <01040610574104.01958@area51.cybersydney.com.au> Content-Transfer-Encoding: 8bit X-Archive-Number: 200104/3 X-Sequence-Number: 256 Hey, try LIKE.. so.. $query = "SELECT * FROM table2 WHERE surname LIKE '%$name%'"; the % before matches anything before $name (so goldsmith would match), % after matches anything after $name (so smithsonian matches).. Check out http://www.postgresql.org/docs/aw_pgsql_book/node51.html for more info.. HTH Chris. > I am trying to find the syntax to pass a wildcard query through to > postgres. Basically I just want to use the user input as a substring of the > actual query to postgres. > It can even be simpler, I realy only need the wildcard at end of the input > string > > i.e. user inputs Smith in form, I want to pick up Smith & Smithsonian. > > Right now I have: > > if ( strlen($NAME) >0): > $NAME = addslashes($NAME); > $NAME = strtolower($NAME); / > $NAME = ucfirst($NAME); //translation final to Upper 1st letter > rest lower as per db format. > > $conn = pg_Connect("dbname=damn_db port=5432"); > if(!$conn) { echo "Error in connecting to DB\n"; exit; } > $result = pg_Exec($conn, "SELECT * FROM table2 WHERE surname = > '$NAME' "); > For whatever reason the *~ matching does not work in PHP4 (ie surname *~ ) > (or more precisely I can't get it to work) > > Any suggestions?