By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,403 Members | 891 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,403 IT Pros & Developers. It's quick & easy.

Help req: PHP and pattern matching.

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
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.