开发者

Realtime MySQL search results on an advanced search page

开发者 https://www.devze.com 2022-12-29 11:04 出处:网络
I\'m a hobbyist, and started learning PHP last September solely to build a hobby website that I had always wished and dreamed another more competent person might make.

I'm a hobbyist, and started learning PHP last September solely to build a hobby website that I had always wished and dreamed another more competent person might make.

I enjoy programming, but I have little free time and enjoy a wide range of other interests and activities.

I feel learning PHP alone can probably allow me to create 98% of the desired features for my site, but that last 2% is awfully appealing:

The most powerful tool of the site is an advanced search page that picks through a 1000+ record game scenario database. Users can data-mine to tremendous depths - this advanced page has upwards of 50 different potential variables. It's designed to allow the hardcore user to search on almost any possible combination of data in our database and it works开发者_C百科 well. Those who aren't interested in wading through the sea of options may use the Basic Search, which is comprised of the most popular parts of the Advanced search.

Because the advanced search is so comprehensive, and because the database is rather small (less than 1,200 potential hits maximum), with each variable you choose to include the likelihood of getting any qualifying results at all drops dramatically.

In my fantasy land where I can wield AJAX as if it were Excalibur, my users would have a realtime Total Results counter in the corner of their screen as they used this page, which would automatically update its query structure and report how many results will be displayed with the addition of each variable. In this way it would be effortless to know just how many variables are enough, and when you've gone and added one that zeroes out the results set.

A somewhat similar implementation, at least visually, would be the Subtotal sidebar when building a new custom computer on IBuyPower.com

For those of you actually still reading this, my question is really rather simple:

Given the time & ability constraints outlined above, would I be able to learn just enough AJAX (or whatever) needed to pull this one feature off without too much trouble? would I be able to more or less drop-in a pre-written code snippet and tweak to fit? or should I consider opening my code up to a trusted & capable individual in the future for this implementation? (assuming I can find one...)

Thank you.


This is a great project for a beginner to tackle.

First I'd say look into using a library like jquery (jquery.com). It will simplify the javascript part of this and the manual is very good.

What you're looking to do can be broken down into a few steps:

  1. The user changes a field on the advanced search page.
  2. The user's browser collects all the field values and sends them back to the server.
  3. The server performs a search with the values and returns the number of results
  4. The user's browser receives the number of results and updates the display.

Now for implementation details:

  1. This can be accomplished with javascript events such as onchange and onfocus.
  2. You could collect the field values into a javascript object, serialize the object to json and send it using ajax to a php page on your server.
  3. The server page (in php) will read the json object and use the data to search, then send back the result as markup or text.
  4. You can then display the result directly in the browser.

This may seem like a lot to take in but you can break each step down further and learn about the details bit by bit.


Hard to answer your question without knowing your level of expertise, but check out this short description of AJAX: http://blog.coderlab.us/rasmus-30-second-ajax-tutorial

If this makes some sense then your feature may be within reach "without too much trouble". If it seems impenetrable, then probably not.

0

精彩评论

暂无评论...
验证码 换一张
取 消