0

Below is a preview of what I have. What I want to do is when someone changes the drop down to "Cooper" then only Cooper brand tires will show, it will have to update my MySQL query. If they change it back to "All Tire Brands" then it does a quick refresh and shows every one of them.

Is something like this possible? If someone can point me in the right directions I would really appreciate it.

Thanks!

enter image description here

7
  • If you are loading all brands (presumably all records) from the DB first view, why mess with SQL at all past that. Just hide/show the rows you want to 'filter' out. This will ultimately reduce the total number of DB calls you make, and should increase performance. Commented Sep 27, 2011 at 13:03
  • That could work too, I am just looking for the best way possible. If I do it that way will that mess up my Pagination at the bottom? Commented Sep 27, 2011 at 13:08
  • Not necessarily. Just write your pagination to show hide the applicable rows. I wish I had a working example, I do this for a small table we have on a piece of client software. If you would like I can help you with this. Commented Sep 27, 2011 at 13:18
  • I would love some help. I wouldn't mind giving you some money for your time either. Whats the best way to get in touch? Commented Sep 27, 2011 at 13:37
  • Umm, I'm not quite sure how to turn this into a chat hehe. Commented Sep 27, 2011 at 13:41

2 Answers 2

1
$("#selectMenuId").bind("change", function(event) {
    var selectedID = event.target.value;
    $.post("path/to/your/serverSide.php", {
        selectionID: selectedID
    }, function(data) {
        $("#myContainer").html(data);
    });
});

And on serverSide.php you would want to do something like this

if(isset($_POST["selectionID"])) {
    $sql = "SELECT * FROM someTable WHERE category_id = " . $_POST["selectionID"] . ";
    // run your query, build your new results, echo them back.
}

The basic id is you are passing the selected value to the serverSide page, running a query against the DB with the (i would assume some sort of category ID) value, build your new resultset and return it. Without knowing how you are building the list currently I wouldn't be able to help further.


Edit To show a loader you can do something like this?

$("#selectMenuId").bind("change", function(event) {
    var selectedID = event.target.value;
    var container = $("#myContainer");
    container.html("Loading...");
    $.post("path/to/your/serverSide.php", {
        selectionID: selectedID
    }, function(data) {
        container.html(data);
    });
});

Or you can have a overlay with a loading gif, and just $("#loadingLayer").show()/.hide() for that.

as for the default selection.. you could (using your ServerSide language) have the default view rendered on the page. or you can have it collected via JS the same way you have the rest of your results... just wait for the list to load and trigger a 'change'

$("#selectMenuId").bind("change", function(event) {
    var selectedID = event.target.value;
    var container = $("#myContainer");
    container.html("Loading...");
    $.post("path/to/your/serverSide.php", {
        selectionID: selectedID
    }, function(data) {
        container.html(data);
    });
}).trigger("change");

Hope this helps!

Sign up to request clarification or add additional context in comments.

3 Comments

Is it possible to not have a separate page, the serverSide.php? I always have trouble getting my MySQL queries when it is on its own page.
Actually I got it working! Wow thanks a bunch. Is there a way to show an AJAX loader while it waits? It takes a few seconds, I just want them to know that it is coming.
Yeah just a loader and then the only other thing is that when I first go to the page it doesn't load anything.. I have to choose a drop down, and then choose "All Tire Brands" to view them all.
0

Sure, it's possible.

You'll need to assign a javascript event listener to the popup. When a visitor selects an item from the popup, you'd use an AJAX call to ask a web service on the server which items to display. (Your Javascript framework of choice -- jQuery, Prototype, or others -- will help with this.) Then you'd replace the search result items in the DOM with those that the web service returned.

That's a high-level conceptual view. If you'd like more details, here's an article that's pretty close to what you need.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.