What's the easiest way for me to perform a search on a set of data
We have a set of data (just names of places) but there are in excess of 25k+. I have been asked if there is a way (there always is), of searching this data and then returning a value from this data based on user input.
Now my skills really lie in XHTML and CSS and I can dabble in JSP and JQuery but I'm not sure of the best approach for this. Could we:
Store the data in an access database and then write a query to select a value based on user input? This output would then need to be displayed on a webpage. What language would this need to be done in though?
I have found a JQuery 'Quicksearch' plugin which I think is excellent (http://lomalogue.co开发者_如何学运维m/jquery/quicksearch/super_table.html)
Now I like the idea of 2) as it's done in JQuery but I don't think it's feasible for this size of data, especially not as the page would be HUGE (though I assume some of the data could be hidden). Is there an easier approach? Am I missing something?
Appreciate that this could be deemed vague so apologies but I don't know what the best approach would be.
Thanks
From what little I know of the project you are working on, it seems best to divide the data into (perhaps geographically-based) chunks. By state/province or by types of places, perhaps. You could then devise simple SQL Queries to pull out long lists of places from the database based on this sorting criteria. These would allow you to pull manageable amounts of data into the page. Which chunk of data is returned could be based on the visitors geo-location or based on user input ('Select a region'). This data could be moved to the page via AJAX: http://api.jquery.com/jQuery.ajax/
I envision the visitor selecting a region. Doing so triggers the AJAX request, which sends to a PHP script which uses that 'region' in an SQL Query, which returns all place names in that region to the PHP script. Once the script is done, the AJAX request (which will wait patiently for the script to finish) will grab all that data as HTML and pull it back to the page. It would then be up to jQuery on the page to format this into a table and then QuickSearch does it's magic.
Alternately, you can have PHP return the data as JSON, which would make the data much more manageable once it's back on the page. This, however, would require a familiarity with JSON and how to use it in jQuery/javascript.
If it's ok, it would be best to have this done server-side in which case you should store your data into a database. You'll use SQL statements to query entries from the database (it's not that hard to learn basic SQL). The SQL statements will embedded in whichever server-side scripting language you're using (PHP, JSP, etc). Just look in your language's documentation at how to access databases.
Storing/hiding the data in the web page and then searching it using Javascript/JQuery will be very slow (at least 10 seconds or so). It's do-able and not particularly difficult, but for most applications that kind of sluggishness is not acceptable.
tskuzzy is right, but left out a crucial bit - this is the type of thing that AJAX works really nicely for. You can store the data in the database, and retrieve it on the server side. You can use AJAX to pass the user value back and forth, and to get the response from the server, and then use jquery/javascript to display the results when they come in. That way, you wont have constant pageloads flying around.
精彩评论