Fastest way to do database / array search

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • richard.pasco@gmail.com

    Fastest way to do database / array search

    Hey all

    I am trying to write a script that allows users to search through a
    database of names. But rather than give a search string and then return
    all those that match, I would like it to search each time the user
    types a new letter in the text box.

    That's badly explained - this example might help!

    The user types "r" and I displays all the names with r in them. The
    user continues and types "i" so the textbox shows "ri" and displayed
    are all the results with "ri" in them. I as doing currently this by
    re-querying the SQL database where the names are hosted but it takes
    too long to query, return and refresh the page.

    What would be a better way of storing this database info to allow a
    faster search? Maybe load it into a PHP array first (stored in another
    file) and search within that? (Can you do 'clever' searches in PHP?) Or
    into a javascript array? The list could be upwards of 1000 names.

    The databse shouldn't change that often so I could have a script that
    updates the array every 24 hours or every time a new name is added.

    Thanks in advance

  • Robertico

    #2
    Re: Fastest way to do database / array search

    I only can offer you a link:


    I hope it's usefull.

    Robertico


    Comment

    • Colin McKinnon

      #3
      Re: Fastest way to do database / array search

      richard.pasco@g mail.com wrote:
      [color=blue]
      > That's badly explained - this example might help!
      >
      > The user types "r" and I displays all the names with r in them. The
      > user continues and types "i" so the textbox shows "ri" and displayed
      > are all the results with "ri" in them. I as doing currently this by
      > re-querying the SQL database where the names are hosted but it takes
      > too long to query, return and refresh the page.
      >[/color]

      Have a google for 'AJAX PHP'

      C.

      Comment

      • Jerry Stuckle

        #4
        Re: Fastest way to do database / array search

        richard.pasco@g mail.com wrote:[color=blue]
        > Hey all
        >
        > I am trying to write a script that allows users to search through a
        > database of names. But rather than give a search string and then return
        > all those that match, I would like it to search each time the user
        > types a new letter in the text box.
        >
        > That's badly explained - this example might help!
        >
        > The user types "r" and I displays all the names with r in them. The
        > user continues and types "i" so the textbox shows "ri" and displayed
        > are all the results with "ri" in them. I as doing currently this by
        > re-querying the SQL database where the names are hosted but it takes
        > too long to query, return and refresh the page.
        >
        > What would be a better way of storing this database info to allow a
        > faster search? Maybe load it into a PHP array first (stored in another
        > file) and search within that? (Can you do 'clever' searches in PHP?) Or
        > into a javascript array? The list could be upwards of 1000 names.
        >
        > The databse shouldn't change that often so I could have a script that
        > updates the array every 24 hours or every time a new name is added.
        >
        > Thanks in advance
        >[/color]

        There's going to be a huge amount of overhead here. But you can do it
        with a combination of javascript and php.

        The javascript will need to monitor the entry field for changes. When
        the field changes, the javascript will have to submit the page to the
        web server. PHP on the server can take the input data, search the
        database and return the (same) page with the updated data.

        But as I said - a huge amount of overhead. And even on a high speed
        link, you're response time will probably be too slow for a touch typist.


        --
        =============== ===
        Remove the "x" from my email address
        Jerry Stuckle
        JDS Computer Training Corp.
        jstucklex@attgl obal.net
        =============== ===

        Comment

        • Chung Leong

          #5
          Re: Fastest way to do database / array search

          Javascript is the way to go from a user-friendliness standpoint. Just
          load the list then dump it into a Javascript array. Or to speed things
          up a little, break the list into multiple arrays based on the first
          letter, and put them into an associative array of arrays.

          Comment

          • richard.pasco@gmail.com

            #6
            Re: Fastest way to do database / array search

            That's what it does at the moment but like you say it's miles behind
            the typist. Will try the javascript list thing and see how that goes....

            Comment

            • Jerry Stuckle

              #7
              Re: Fastest way to do database / array search

              richard.pasco@g mail.com wrote:[color=blue]
              > That's what it does at the moment but like you say it's miles behind
              > the typist. Will try the javascript list thing and see how that goes....
              >[/color]

              Richard,

              The javascript won't help you much, either - unless you send the entire
              list to the user - which can take a long time if they're on a dial up line.

              This type of filtering is very nice - but is really only suitable for
              local access. It just doesn't work well on remote access.

              --
              =============== ===
              Remove the "x" from my email address
              Jerry Stuckle
              JDS Computer Training Corp.
              jstucklex@attgl obal.net
              =============== ===

              Comment

              Working...