Hi all of you !!
I have a column in a table which has data seperated by spaces like this -->
AS DD QW-02-44 WE
FG QW-02-44 RE WE
QW WQ
I am implementing a search functionality wherein a user will enter some data in a textbox to search.
For eg:- if the user wants to retreive rows which have WQ in them then the result should be 3rd row above.
How to do this ?
Platform --> Debian Sarge
Language --> Perl CGI
11 3790
There are different ways of doing this, such as using the LIKE attrib or a regular expression. The following samples show each method (I personnaly favor the regular expression method). - $search = 'WQ';
-
$sql1 = 'SELECT * FROM table ';
-
$sql1.= 'WHERE column REGEXP "' . $search . '"';
-
-
or
-
-
$sql2 = 'SELECT * FROM table ';
-
$sql2.= 'WHERE column LIKE "%' . $search . '%"';
-
Ronald :cool:
There are different ways of doing this, such as using the LIKE attrib or a regular expression. The following samples show each method (I personnaly favor the regular expression method). - $search = 'WQ';
-
$sql1 = 'SELECT * FROM table ';
-
$sql1.= 'WHERE column REGEXP "' . $search . '"';
-
-
or
-
-
$sql2 = 'SELECT * FROM table ';
-
$sql2.= 'WHERE column LIKE "%' . $search . '%"';
-
Ronald :cool:
Suppose I want to search WQ QW(random) then also I want the 3rd row .
How to do that ?
Depends on whether you want to test for one string 'WQ QW' or for 2 separate strings 'WQ' and 'QW'. - $search1 = 'WQ';
-
$search2 = 'QW';
-
$search3 = 'WQ QW';
-
-
// search for 1 string 'WQ QW'
-
$sqla = 'SELECT * from table ';
-
$sqla .= 'WHERE column REGEXP "' . search3 . '" ';
-
-
// search for 2 strings 'WQ' and 'QW'
-
$sqlb = 'SELECT * from table ';
-
$sqlb .= 'WHERE column REGEXP "' . search1 . '" ';
-
$sqlb .= 'AND column REGEXP "' . $search2 . '" ';
-
Ronald :cool:
Depends on whether you want to test for one string 'WQ QW' or for 2 separate strings 'WQ' and 'QW'. - $search1 = 'WQ';
-
$search2 = 'QW';
-
$search3 = 'WQ QW';
-
-
// search for 1 string 'WQ QW'
-
$sqla = 'SELECT * from table ';
-
$sqla .= 'WHERE column REGEXP "' . search3 . '" ';
-
-
// search for 2 strings 'WQ' and 'QW'
-
$sqlb = 'SELECT * from table ';
-
$sqlb .= 'WHERE column REGEXP "' . search1 . '" ';
-
$sqlb .= 'AND column REGEXP "' . $search2 . '" ';
-
Ronald :cool:
Thanks Ronald for that.
This is what I wanted.
I like the smiley beside your name . :-D
Glad I could help you out.
Ronald :cool:
One more problem --> *europe should match "DD EASTEUROPE" and not
"WE EUROPE" (ignore spaces).
How to do this ?
ok no need to think I got -->
$textbox =~ s/\s/[^[:space:]]/g;
$sqla = 'SELECT * from table ';
$sqla .= 'WHERE column REGEXP "$textbox" ';
Hi Friends,
i am having one trigger with all insert ,update and delete opreations, then how to call this trigger from user form.
environment is :
ASP.NET with C#
Sql Server
kindly help me inthis regard.
thanks
viswanath.
viswanatareddy:
You are
(a) in the wrong thread (this thread has nothing to do with triggers).
(b) in the wrong forum (post your question in SQL server or .NET forum)
Ronald :cool:
Ronald,
may i know why you personally favour the regular expression method ?
Ronald,
may i know why you personally favour the regular expression method ?
The main reason why I prefer a REGEXP above the LIKE is that it gives more flexibility as opposed to a more rigid matching with LIKE. These reasons are (MySQL doc): - classes: in my opinion the most important one. A character class ‘[...]’ matches any character within the brackets.
For example, ‘[abc]’ matches ‘a’, ‘b’, or ‘c’. To name a range of characters, use a dash. ‘[a-z]’ matches any letter, whereas ‘[0-9]’ matches any digit.
- no of instances: Also important to me. ‘*’ matches zero or more instances of the thing preceding it.
For example, ‘x*’ matches any number of ‘x’ characters, ‘[0-9]*’ matches any number of digits, and ‘.*’ matches any number of anything.
- position: a REGEXP pattern match succeeds if the pattern matches anywhere in the value being tested. (This differs from a LIKE pattern)
See also the MySQL documentation on Regular Expressions
Ronald :cool:
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Sharif T. Karim |
last post by:
I am trying to do the following with my search script that looks for records
in a mysql table. The following is an example of what I am trying to do.
Text being searched:
--
The brown fox...
|
by: Vamsee Krishna Gomatam |
last post by:
Hello,
I'm having some problems understanding Regexps in Python. I want
to replace "<google>PHRASE</google>" with
"<a href=http://www.google.com/search?q=PHRASE>PHRASE</a>" in a block of
text....
|
by: Andrew Crowe |
last post by:
Hi guys,
I have a table currently set up like this:
<- ->
video
------
video_id
|
by: Phlip |
last post by:
C++ers:
Here's an open ended STL question. What's the smarmiest most templated way
to use <string>, <algorithms> etc. to turn this:
" able search baker search charlie "
into this:
" able...
|
by: Alphonse Giambrone |
last post by:
Is there a way to use multiple search patterns when calling
Directory.GetFiles.
For instance Directory.GetFiles("C:\MyFolder", "*.aspx") will return all
files with the aspx extension.
But what if...
|
by: news |
last post by:
We're trying to make a search form, and are wanting to create links for
all the letters a person can click on and will bring up all entries
that start with that letter.
That part is easy:
.......
|
by: jrs_14618 |
last post by:
Hello All,
This post is essentially a reply a previous post/thread
here on this mailing.database.myodbc group titled:
MySQL 4.0, FULL-TEXT Indexing and Search Arabic Data, Unicode
I was...
|
by: FluffyCat |
last post by:
Last month I continued my series of design patterns examples using PHP
5 with the Observer Pattern and the Prototype Pattern. Here now is my
16th example, the Adapter pattern.
...
|
by: Eric |
last post by:
Hi: I have two files. I search pattern ":" from emails text file and
save email contents into a database. Another search pattern " field is blank. Please try again.",
vbExclamation + vbOKOnly...
|
by: |
last post by:
Hello...
i have a table which contains a column named "ask" and a column named
"per"...
my think is that i want to search in "ask" and echo the data stored in "per"
for this entry...
How do i do...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |