Help req: PHP and pattern matching.

This is a discussion on Help req: PHP and pattern matching. within the PHP Language forums, part of the PHP Programming Forums category; Despite looking at a number of tutorials in books and online examples on pattern matching - I can't quite get ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 03-07-2004
Dariusz
 
Posts: n/a
Default 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
Reply With Quote
  #2 (permalink)  
Old 03-07-2004
Joachim Mæland
 
Posts: n/a
Default Re: Help req: PHP and pattern matching.

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

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 07:13 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0