Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > PHP Databases
|
PHP Databases Using PHP in conjunction with databases. PHP questions not specific to databases should be directed to one of the other PHP forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 18th, 2004, 09:48 AM
Authorized User
 
Join Date: Aug 2003
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to spraveens
Default Pattern Matching using PHP

Hi
I am implementimg a project where by the user enters some pattern of string ,Now I have to write a query where by the user entered string is searched or compared with a particular field in the Access Database.I have writen the following query :

$opr=$_POST["txtquery"];
$sql="select * from datadump where myfield like '$opr'";
$rs=odbc_exec($conn,$sql);

Now the query returns results only if it finds an 'exact' match ,I want to write a query where by all the records having the user entered string are returned.How do I do it??(I am using php/access)

Thankz.
Praveen
 
Old March 18th, 2004, 02:02 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Mmmm, I use MySQL, but I bet its the same...

SELECT * FROM datadump WHERE myfield LIKE '%$opr%'

This should work if Access is the same as MySQL.

HTH,

----------
---Snib---
----------

<><
 
Old March 23rd, 2004, 10:03 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts
Default

More info: The % character is a wildcard character that matches "zero or more characters". That's why the above query (with the %s) works. The query says:

Give me all the rows where the contents of myfield are "<anything>opr<anything>"

You can also use wildcards to search for things that are at the end:
  SELECT * FROM table WHERE col = '%pear tree.'

or at the beginning:
  SELECT * FROM table WHERE col = 'On the first%'



Take care,

Nik
http://www.bigaction.org/





Similar Threads
Thread Thread Starter Forum Replies Last Post
Find Matching pattern in Given String sanjivbshinde ASP.NET 2.0 Professional 3 October 10th, 2008 06:32 PM
Pattern Matching for Sequentinal numbers like 1234 sriram_r15 Beginning PHP 3 January 20th, 2005 05:46 PM
javascript pattern matching... rbd Javascript 1 October 7th, 2004 12:20 PM
Question on Pattern matching using VBscript Dereksam VBScript 1 September 9th, 2004 04:45 AM
PHP Pattern Matching joanncae BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 1 May 17th, 2004 04:52 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.