Hi there,

I have a mysql database which i query to get records from multiple tables. The retrieved record set is then stored in a javascript array in the client side.
What i want to do is use javascript so that the user can select an option from a drop down menu and based on what he chooses, different rows from the data set are displayed.

Hope it is a clear description.

Any thoughts whould be very much appreciated?

    Ajax will do this plus its a buzzword! Prototype includes a pretty easy ajax library.

    Download prototype here
    http://prototype.conio.net/

    Its documented here
    http://wiki.script.aculo.us/scriptaculous/show/Prototype

    and here
    http://www.sergiopereira.com/articles/prototype.js.html

    What you want to read up on is the ajax object, which is actually pretty darn easy to use.

    You will need 2 php pages, one that creates the html page, and a second that serves up the results from your database as just body html (without head, body, etc). Here is the process

    1. The initial page is generated with your dropdown list and a div tag for the contents of the dataset.

    2. When the user clicks on the select button an even fires which runs the ajax request object. This will request your php service page and pass the id of the selected item.

    3. Your php service receives the request and queries the db for only the needed records, it then returns them by echoing them as content html.

    4. The ajax updater object then receives the output from the php service page. It then magically sticks this into the body of your page in the selected div without any refreshes.

    The other method is to create giant javascript arrays with your data, or make it so every time they click on the select box the page refreshes. The latter is the easiest, I wouldn't even mess around with javascript arrays if you can help it.

      I will take a closer look at your links, they seem promising.

      I really appreciate your help,

      Thank you very much.

        Excellent! Even if you don't use it for ajax I think you might find prototype is something you can't live without. I use it all the time just for the $() and $F() functions which make life a lot easier and code a lot cleaner.

          Write a Reply...