Re: Searching a MySQL database?

From: Date: Sun, 14 Jan 2001 22:18:49 +0000
Subject: Re: Searching a MySQL database?
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-34509@lists.php.net to get a copy of this message
> > towns = '$town' > > ...and... > > towns LIKE '$town' > > > > ...are essentially the same without the % wildcard character. Thus, > > > > towns = '$town' > > ...is much different than... > > towns LIKE '%$town%' > > How different are they? I'm not even sure what a wildcard is....? A wildcard is a character that can be used to represent any character (or any set of any character). For instance, on many operating systems the * wildcard represents what you could call "anything". So * is anything from the empty string ('') to anything ('Toby Butzon'). '*zon', however, would match only strings ending in 'zon'; thus, 'Toby Butzon' would match but 'Joe Smith' would not. In SQL, the % symbol is used as the * wildcard. Consider the following: (id) bases ------------- (1) Ft. Worth (2) Ft. Benning Here are some queries of the above table with their results.... bases='Ft. Worth' returns record 1 bases LIKE '%Worth%' returns record 1 bases LIKE '%Ft.%' returns 1 & 2 bases LIKE '%' returns all records (in this case, 1 & 2) See? > And thanks ;) Of course. --Toby

« previous php.general (#34509) next »