467,169 Members | 1,013 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,169 developers. It's quick & easy.

Help req: PHP and pattern matching.

Despite looking at a number of tutorials in books and online examples on
pattern matching - I can't quite get my head around it to work... so need
some help.

What I have now is a variable that is POST'ed to a PHP script and I want
the script to go through a database to search through to check if a certain
value is entered in a field, if yes - echo the entire row, if not, move
onto the next record to check.

So far I have managed to write a script that would search each record in
turn of the database - but need something to perform a pattern match. I
have seen a function called preg_grep() but there are no really good
examples, especially on how to construct a pattern search term in the
first place.

Back to the problem, the POST to the PHP script would have a value of say
"video", but the database could have values for that field of "video021" or
"audio005" or "screensaver010" etc.. (file type and file number).

So I need to match the first part of the file ID (and exclude the file
number, ie. "video" and not "video021")... then echo the row each time the
script found a match for "video" and move onto the next row for other
instances of "video" to echo.

Any help appreciated.

Dariusz
Jul 17 '05 #1
  • viewed: 1795
Share:
1 Reply
On Sun, 07 Mar 2004 10:07:41 +0000, Dariusz wrote:
Back to the problem, the POST to the PHP script would have a value of
say "video", but the database could have values for that field of
"video021" or "audio005" or "screensaver010" etc.. (file type and file
number).

So I need to match the first part of the file ID (and exclude the file
number, ie. "video" and not "video021")... then echo the row each time
the script found a match for "video" and move onto the next row for
other instances of "video" to echo.


Using MySQL? IMHO it's better to leave this to the db-engine...

SELECT ID, field_1 FROM video_tbl WHERE ID LIKE '%video%';

Also check the MySQL manual for Fulltext for a more "search engine like"
functionality.

--
mvh/regards
Joachim Mæland

If everything seems under control, you're just not going fast enough.
-Mario Andretti

Jul 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

9 posts views Thread by Xah Lee | last post: by
10 posts views Thread by bpontius@greateastsoftware.com | last post: by
2 posts views Thread by Mortimer Schnurd | last post: by
1 post views Thread by Rahul | last post: by
2 posts views Thread by Ole Nielsby | last post: by
9 posts views Thread by Simon Woods | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.