38 users online (1 members and 37 guests)  


  Results 1 to 9 of 9

Related

  1. Problem in saving data    Forum: PHP Forum
    Replies: 1
  2. Replies: 1
  3. Random pictures in each table data cell    Forum: HTML Forum
    Replies: 0
  4. Matching a certain date format from a String?    Forum: CGI Perl Forum
    Replies: 0
  1. #1
    vids_cs's Avatar
    New User

    Status
    Offline
    Join Date
    Oct 2006
    Posts
    4

    Please Help problem fetching data from table (String Matching)

    Hi guys ,
    Here is my problem,
    I have a table named abc which have a column id_number
    table abc
    -----------------------------------------------
    |id_number name
    ----------------------------------------
    012 albert
    014 sam
    045 anthony
    023 john
    ----------------------------------
    and I have some string suppose 023456987
    Now what i have to do is to select the values from table which matches to the string .
    in this case it should display 023 john

    I am trying this query:
    select * from abc where '023456987' like id_number+'%';
    this query works fine in MSSQL server but doesn't works in MYSQL.

    Please solve this problem how can i get the wanted result.
    Thanks In Advance.
    vids

  2. #2
    vinyl-junkie's Avatar
    Moderator

    Status
    Offline
    Join Date
    Sep 2005
    Posts
    721

    Re: Please Help problem fetching data from table (String Matching)

    Do you want to match the whole string or just a substring? You won't get a match with 023 john for that whole string.
    Music Around The World - Collecting tips, trade
    and want lists, album reviews, & more

  3. #3
    vids_cs's Avatar
    New User

    Status
    Offline
    Join Date
    Oct 2006
    Posts
    4

    Re: Please Help problem fetching data from table (String Matching)

    HI vinyl-junkie ,

    First of all Thanks a lot.
    whole string from table should match to the external string.

    suppose external string is 023456 and the entries in table are 023 and 0234 then it should select 0234.

    Can I get you online on yahoo.My yahoo id is vids_cs@yahoo.com

  4. #4
    vinyl-junkie's Avatar
    Moderator

    Status
    Offline
    Join Date
    Sep 2005
    Posts
    721

    Re: Please Help problem fetching data from table (String Matching)

    Sorry, I don't use IM. I also prefer to give answers publicly on the forum, so that others may possibly benefit from the answers as well.

    Your select statement should look something like this, if I understand correctly what you're saying.

    Code:
    select * from abc where id_number like '%023%'
    or whatever string it is you're trying to select.

    Hope this helps.
    Music Around The World - Collecting tips, trade
    and want lists, album reviews, & more

  5. #5
    vids_cs's Avatar
    New User

    Status
    Offline
    Join Date
    Oct 2006
    Posts
    4

    Re: Please Help problem fetching data from table (String Matching)

    No i think you did not understand properly let me explain again
    I have a number in a variable suppose $A= 023897487

    now what i have to do is to check the most matching value from the field id_number
    suppose
    id_number
    -------------------
    023
    0238
    0245
    02356
    0123

    So if the number
    $ A=023897487 then it should select 0238
    if $ A=0235496487 then it should select 023
    if $ A=0235696487 then it should select 02356
    if $ A=01234697487 then it should select 0123

    I hope you understand the problem now .


    Thanks

  6. #6
    vinyl-junkie's Avatar
    Moderator

    Status
    Offline
    Join Date
    Sep 2005
    Posts
    721

    Re: Please Help problem fetching data from table (String Matching)

    If I understand what you're telling me, you're matching on the sequence of numbers and not the variable itself. I'm sure there's a way of doing it, but it would likely involve some pretty extensive coding. Maybe you could do it with a regular expression, but I'm no good at that.
    Music Around The World - Collecting tips, trade
    and want lists, album reviews, & more

  7. #7
    DeadMeatGF's Avatar
    Moderator

    Status
    Offline
    Join Date
    Sep 2005
    Posts
    381

    Re: Please Help problem fetching data from table (String Matching)

    I agree with vinyl - it looks perfect for reg-ex - but there's whole books just on that topic, and I'm not knowledgeable in this area.

  8. #8
    vids_cs's Avatar
    New User

    Status
    Offline
    Join Date
    Oct 2006
    Posts
    4

    Re: Please Help problem fetching data from table (String Matching)

    hmm then its my badluck .

    Anyways thank you for you help

  9. #9
    DeadMeatGF's Avatar
    Moderator

    Status
    Offline
    Join Date
    Sep 2005
    Posts
    381

    Re: Please Help problem fetching data from table (String Matching)

    I discovered this site - looks like this could be the place to look for a solution ...
    http://regexlib.com/



Tags for this Thread