Results 1 to 2 of 2
  1. #1
    Join Date
    Jun 2011

    Unanswered: 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

  2. #2
    Join Date
    Apr 2002
    Toronto, Canada
    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 | @rudydotca
    Buy my SitePoint book: Simply SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts