If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Trouble with MySQL query

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-27-11, 07:08
springmedia springmedia is offline
Registered User
 
Join Date: Jun 2011
Posts: 1
Trouble with MySQL query

Hi there guys, I am having a little trouble with the following query.

$result = mysql_query("SELECT * FROM members WHERE location1 LIKE '$term' OR location2 LIKE '$term' OR location3 LIKE '$term' OR location4 LIKE '$term' OR location5 LIKE '$term' OR location6 LIKE '$term' OR location7 LIKE '$term' OR location8 LIKE '$term' OR location9 LIKE '$term' OR location10 LIKE '$term' ")
or die(mysql_error());

I have 10 locations with a prefix's defined within the database, these are for post code areas.

e.g. Aberdeen = AB

At the moment I am getting the correct results if the user submits for form with $term = AB but if someone types AB1 this will fail and not return any results. Not sure if there is anyway that I can trim the $term to allow 2 char's. If I use the wild card % I will receive too many results as a will exist within another post area. e.g. LA.

Kind of stuck at the moment of where to go.

Any help would be much appreciated.

Kind Regards,

Rich Lacey
Reply With Quote
  #2 (permalink)  
Old 06-27-11, 07:32
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
why does a member have 10 locations? what are you gonna do when a member comes along who has 11 locations?

do a search for first normal form and then please redesign your table before proceeding any further with your query
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
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 On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On