Dominik:

If you're comfortable using the json_encode function in PHP 5.2.0, you
could do the following:

Client Side (each id for <select>, #company for <ul>):
$(function(){
$("#category").change(function(){
  $.getJSON('myapp.php',{category:$(this).val()},function(json){
  $("#state").empty();
  foreach(state in json) {
    $("#state").append('<option value="'+state+'">'+json[state]+'</option>');
  }
});

$("#state").change(function(){
  $.getJSON('myapp.php',{state:$(this).val()},function(json){
  $("#zip").empty();
  foreach(zip in json) {
    $("#state").append('<option value="'+zip+'">'+json[zip]+'</option>');
  }
});

$("#zip").change(function(){
$.getJSON('myapp.php',{category:$("#category").val(),state:$("#state").val(),zip:$(this).val()},function(json){
  $("#company").empty();
  foreach(company in json) {
    $("#company").append('<li>'+json[company]+'</li>');
  }
});
});

Server Side, using php:
switch(true) {
case ($_REQUEST['zip']):
  // Generate list of companies using category, state and zip
  break;
case ($_REQUEST['state']):
  // Generate list of zip codes, using state
  break;
case ($_REQUEST['category']):
  // Generate list of states, using category
  break;
}

echo json_encode($database_output);

I know this example is lacking a bit on the specifics, but hopefully
it'll set you in the right direction. Your problem is easy to solve
when using getJSON/json_encode combination.

- jake

On 2/13/07, Dominik Hahn <[EMAIL PROTECTED]> wrote:
> Hello there!
>
> I've already searched for a plugin but I'm afraid that nobody has faced this
> challenge before. :-(
>
> I have a lot of database entries and I want to make them selectable like so:
>
> The first selectbox shows all available categories. This doesn't require
> jQuery - it's good old PHP. ;-)
>
> When I select Category A from that selectbox, jQuery should now generate a
> new selectbox with the list of states in which the companies in the selected
> category are.
>
> When I select a state it should generate a second selectbox with a list of
> postal codes in which the companies in the selected state are so that a user
> can select a nearby company.
>
>
>
> CATEGORY (select Category A, it generates a new selectbox)
>
> -> STATE (contains the states of all companies that are listed under
> Category A, generates a new selectbox containing all postal codes of the
> companies that are listed in Category A and State X)
>
> --> POSTAL CODE (contains all postal codes of the companies that are listed
> in Category A and State X, on select it prints out all companies that are
> listed in Category A and State X,and with the postal code of 123)
>
>
>
> I hope you all got my  bad example! ;-)
>
> Do you now a good and simple way to do it?
>
>
> Thanks in advance,
> Dominik
>
>
>
> _______________________________________________
> jQuery mailing list
> [email protected]
> http://jquery.com/discuss/
>
>

_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/

Reply via email to