pg.ddx.io  pgsql-php@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Wildcard queries via PHP4
7+ messages / 7 participants
[nested] [flat]

* Wildcard queries via PHP4
@ 2001-04-06 00:17  rickf <rickf@dufferinresearch.com>
  0 siblings, 3 replies; 7+ messages in thread

From: rickf @ 2001-04-06 00:17 UTC (permalink / raw)
  To: pgsql-php

Hi,

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?

Many thanks.





_______________________________
Rick Frank
Dufferin Research

mailto:rickf@dufferinresearch.com
________________________________

^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: Wildcard queries via PHP4
@ 2001-04-06 00:57  Chris Smith <csmith@squiz.net>
  parent: rickf <rickf@dufferinresearch.com>
  2 siblings, 0 replies; 7+ messages in thread

From: Chris Smith @ 2001-04-06 00:57 UTC (permalink / raw)
  To: rickf <rickf@dufferinresearch.com>; pgsql-php

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?




^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: Wildcard queries via PHP4
@ 2001-04-06 02:28  Jesus Aneiros <aneiros@ucfinfo.ucf.edu.cu>
  parent: rickf <rickf@dufferinresearch.com>
  2 siblings, 1 reply; 7+ messages in thread

From: Jesus Aneiros @ 2001-04-06 02:28 UTC (permalink / raw)
  To: rickf <rickf@dufferinresearch.com>; +Cc: pgsql-php

You could try LIKE and %, but I think it is ~* and not *~

Saludos, Jesus.

On Thu, 5 Apr 2001, rickf wrote:

> Hi,
> 
> 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?
> 
> Many thanks.
> 
> 
> 
> 
> 
> _______________________________
> Rick Frank
> Dufferin Research
> 
> mailto:rickf@dufferinresearch.com
> ________________________________
> 
> 




^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: Wildcard queries via PHP4
@ 2001-04-06 13:24  Adam Lang <aalang@rutgersinsurance.com>
  parent: rickf <rickf@dufferinresearch.com>
  2 siblings, 0 replies; 7+ messages in thread

From: Adam Lang @ 2001-04-06 13:24 UTC (permalink / raw)
  To: pgsql-php

Use LIKE, as others have mentioned.  The reason the wildcard doesn't work is
because it isn't supposed to.  No SQL should use it.

Adam Lang
Systems Engineer
Rutgers Casualty Insurance Company
http://www.rutgersinsurance.com
----- Original Message -----
From: "rickf" <rickf@dufferinresearch.com>
To: <pgsql-php@postgresql.org>
Sent: Thursday, April 05, 2001 8:17 PM
Subject: [PHP] Wildcard queries via PHP4


> Hi,
>
> 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?
>
> Many thanks.
>
>
>
>
>
> _______________________________
> Rick Frank
> Dufferin Research
>
> mailto:rickf@dufferinresearch.com
> ________________________________
>
>




^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* RE: Wildcard queries via PHP4
@ 2001-04-06 23:39  Jeff Fitzmyers <jeff.fitzmyers@managestar.com>
  0 siblings, 1 reply; 7+ messages in thread

From: Jeff Fitzmyers @ 2001-04-06 23:39 UTC (permalink / raw)
  To: rickf <rickf@dufferinresearch.com>; pgsql-php

This works for me on 7.1 beta 6; php-4.0.4pl1

$sql="SELECT * 
 FROM customer 
 WHERE $look_in ~*'$text' AND
  mbewbe='$mbewbe' AND
  c_state $query_location
 ORDER BY company_name;";

jeff fitzmyers
>>>>

For whatever reason the *~ matching does not work in PHP4 (ie surname *~
)
(or more precisely I can't get it to work >>>>>>



^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: RE: Wildcard queries via PHP4
@ 2001-04-08 23:46  Grant <grant@conprojan.com.au>
  parent: Jeff Fitzmyers <jeff.fitzmyers@managestar.com>
  0 siblings, 0 replies; 7+ messages in thread

From: Grant @ 2001-04-08 23:46 UTC (permalink / raw)
  To: pgsql-php

As far as I know "LIKE" is case sensitive, where as ~* is regular
expression matching and is case insensitive.

On Fri, 6 Apr 2001, Jeff Fitzmyers wrote:

> This works for me on 7.1 beta 6; php-4.0.4pl1
> 
> $sql="SELECT * 
>  FROM customer 
>  WHERE $look_in ~*'$text' AND
>   mbewbe='$mbewbe' AND
>   c_state $query_location
>  ORDER BY company_name;";
> 
> jeff fitzmyers
> >>>>
> 
> For whatever reason the *~ matching does not work in PHP4 (ie surname *~




^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: Wildcard queries via PHP4
@ 2001-11-16 05:50  Peter <peterh@600ml.com.au>
  parent: Jesus Aneiros <aneiros@ucfinfo.ucf.edu.cu>
  0 siblings, 0 replies; 7+ messages in thread

From: Peter @ 2001-11-16 05:50 UTC (permalink / raw)
  To: Jesus Aneiros <aneiros@ucfinfo.ucf.edu.cu>; pgsql-php

yes the easiest way is     select * from table where LIKE '%$NAME%' for case
sensitive search
or        select * from table where ILIKE '%$NAME%'    if the you want to do
a case insensitive search
much, much, much faster than regular expression

regards, Peter


----- Original Message -----
From: "Jesus Aneiros" <aneiros@ucfinfo.ucf.edu.cu>
To: <beloshapka@mnogo.ru>
Cc: <pgsql-php@postgresql.org>
Sent: Friday, April 06, 2001 1:28 PM
Subject: Re: [PHP] Wildcard queries via PHP4


> You could try LIKE and %, but I think it is ~* and not *~
>
> Saludos, Jesus.
>
> On Thu, 5 Apr 2001, rickf wrote:
>
> > Hi,
> >
> > 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);   file://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?
> >
> > Many thanks.
> >
> >
> >
> >
> >
> > _______________________________
> > Rick Frank
> > Dufferin Research
> >
> > mailto:rickf@dufferinresearch.com
> > ________________________________
> >
> >
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster
>
>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org
>




^ permalink  raw  reply  [nested|flat] 7+ messages in thread


end of thread, other threads:[~2001-11-16 05:50 UTC | newest]

Thread overview: 7+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2001-04-06 00:17 Wildcard queries via PHP4 rickf <rickf@dufferinresearch.com>
2001-04-06 00:57 ` Chris Smith <csmith@squiz.net>
2001-04-06 02:28 ` Jesus Aneiros <aneiros@ucfinfo.ucf.edu.cu>
2001-11-16 05:50   ` Peter <peterh@600ml.com.au>
2001-04-06 13:24 ` Adam Lang <aalang@rutgersinsurance.com>
2001-04-06 23:39 RE: Wildcard queries via PHP4 Jeff Fitzmyers <jeff.fitzmyers@managestar.com>
2001-04-08 23:46 ` Grant <grant@conprojan.com.au>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox