Get a specific list of postcodes with MySQL Like Operator

Discussion in 'Databases' started by nita, May 3, 2013.

  1. #1
    Hi everyone.

    I have list of postcodes. And what i'm trying to do is get a listing of similar poscodes only.

    My Code:
    $postcode1 = ereg_replace('[^A-Za-z]', '', $postcode);
     
    SELECT * FROM coverparked WHERE postcode LIKE '$postcode1%' ORDER BY postcode
    Code (markup):
    So then $postcode1 strips all number from postcode, so for example E16 is strpped down to E only, then using the mysql query i get all the postcodes from database starting with E, problem is that i also get listing of postodes starting with EC, EN ... and i want postcodes sarting with E only.

    Tried some options but i can't get to make it work..

    Can you help me out here please ..

    Thanks a lot in advance in advance.
     
    nita, May 3, 2013 IP
  2. modulout

    modulout Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #2
    You can try with mysql REGEXP (http://dev.mysql.com/doc/refman/5.1/en/regexp.html)

    something like: /^e*[0-9]
     
    modulout, May 10, 2013 IP
  3. HuggyStudios

    HuggyStudios Well-Known Member

    Messages:
    724
    Likes Received:
    20
    Best Answers:
    26
    Trophy Points:
    165
    #3
    HuggyStudios, May 12, 2013 IP