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 ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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 |
|
|||
|
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 |