search question

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • yeshello54
    New Member
    • Mar 2009
    • 54

    search question

    hello. I have a question about my search function in my php page. I have a search function that when the user types the ID# in it will return all the data from the database connected to that id#. My problem is that I have over 350 numbers and if I search for instance the number 15 .. it returns all the data for 15,5,150,151. How do I get it to just recognize just the number 15???

    here is the code i use to collect the input number and search table.

    Code:
    $term=$_POST['term'];
    $sql= mysql_query("select * from collection_data  where edwards  like '%$term%'");
    any help would be great thanks.
  • dlite922
    Recognized Expert Top Contributor
    • Dec 2007
    • 1586

    #2
    don't use LIKE comparison in your SQL. use an equal sine: edwards = '$term'

    Please Please PLEASE sanitize your variable before putting them in SQL.

    Read this:




    Dan

    Comment

    • hsriat
      Recognized Expert Top Contributor
      • Jan 2008
      • 1653

      #3
      Use of fulltext search is recommended in such case.

      Comment

      • dlite922
        Recognized Expert Top Contributor
        • Dec 2007
        • 1586

        #4
        Originally posted by hsriat
        Use of fulltext search is recommended in such case.
        in which case? I think he's looking for a boolean search. Either to equal or not equal.


        Dan

        Comment

        • hsriat
          Recognized Expert Top Contributor
          • Jan 2008
          • 1653

          #5
          Originally posted by dlite922
          in which case? I think he's looking for a boolean search. Either to equal or not equal.


          Dan
          I see... I didn't read properly, I thought he was trying to get 15 from within some text.

          Thanks for correcting. :)

          Comment

          Working...