Page 1 of 1
mysql query, search
Posted: Fri Jul 13, 2007 3:32 pm
by truepal20032001
Hello, i want the sql query to search an address in a database, and if it is registered to give an error, else register it,
Code: Select all
SELECT *
FROM `newsletter`
WHERE `address` = CONVERT( _utf8 '$address'
USING latin1 )
COLLATE latin1_german2_ci
LIMIT 0 , 30
but how can i tell it if it finds it,to give an error, else to continues with the code
Posted: Sat Jul 14, 2007 1:17 am
by ocpamit
if u are looking to match postal address with the existing one in the database, its hard as you see there are many ways to write an address like:
274 e block sbs nagar
274 e sbs nagar
e block-274 sbs nagar
u can use "like" operator in the query, but it would n't match exact address.
other way u can explode the input address by space and match each of the array element with like operator in the query using while loop. Then you can use AND condition for all query results to match the address. something like that may work...
Re: mysql query, search
Posted: Sat Jul 14, 2007 1:52 pm
by califdon
truepal20032001 wrote:Hello, i want the sql query to search an address in a database, and if it is registered to give an error, else register it,
Code: Select all
SELECT *
FROM `newsletter`
WHERE `address` = CONVERT( _utf8 '$address'
USING latin1 )
COLLATE latin1_german2_ci
LIMIT 0 , 30
but how can i tell it if it finds it,to give an error, else to continues with the code
You can check
mysql_num_rows() function and if it's zero, there was no match. But as
ocpamit warned, this is probably unworkable because of the possibility of entering an address in so many ways. It is likely to miss finding a match a high percentage of the time.