Forums

Filtering query results with a drop-down choice

mathmathou 04 Oct, 2013
Hello everybody,

After searching through the forum, I decided to post my problem because I was unable to solve it alone.

I have a simple table with data like :
-player name (input_name)
-player alliance (input_ally)
-player coordinates X (input_X)
-player coordinates Y (input_Y)
-player level (input_level)

Very basic indeed ;-)

I setup my form like this :

On load (in the event section), a DB Multi Record Loader populates a Drop Down List with all the "input_ally" records found in the table. This works fine so far : I've put the Drop Down List in the preview section, and a show HTML just under the Multi Record Loader in the event section.

Then, the form user is supposed to select something in the drop down list and then clic on a submit button (also in the preview section, just under the drop down list), resulting in a list of all members of the selected alliance.
(something like "select input_name FROM table_name WHERE input_ally=drop_down_select if you see what I mean).

To achieve that, I put a second DB Multi Record Loader but this time in the On submit part in the event section.

By enabling Data display, I can see that all names are listed, the name queried are not filtered on the choice made by the user in the drop down list.

I probably set up something wrong (like how to link the user selection to the second Multi Record Loader in order for the filter to operate), but after a few hours of try and errors, I decided to submit my problem to the community.

I'm sure it's pretty simple, but I can't get my hands on it.

Thank you in advance for any info you could provide me with on that great tool of yours.

Sincerely yours

Mathmathou

PS : hope you understand my english :-)
GreyHead 04 Oct, 2013
Hi mathmathou,

The DB Multi Record Loader in the On Submit event won't do anything until the form is submitted . . . and by then it is too late to change anything in the Preview window.

There are two solutions to this:

One is to use a multi-page form so that you have the first drop-down on page 1 and use the results from this to load the options you need into the second drop-down on page 2.

The other is to use JavaScript to build a double drop-down so that the options are changed in the browser. Please see this FAQ for more information.

Bob
mathmathou 04 Oct, 2013
Hello GreyHead, and thank you for your fast reply.

I knew my English was not goo enough, and I think I did not explain my problem correctly.😀

There is only one drop down list in my form. It is used (after being populated from a table, this part works...) to make a selection.

Once submitted, the result page should give me a list of results filtered on the choice made in the drop down list.

EXAMPLE
Imagine a database table full of car models with their manufacturers. I want, with the help of a drop down list containing the manufacturers' names, to get a list of all the car models built by the selected manufacturer, and only this one.

Currently, I have achieved all the steps, but the results are not filtered on the manufacturer selected, and they display all the car models 😟

Hope my explanation was clear enough.

Thanks again in advance

Math
GreyHead 06 Oct, 2013
Hi mathmathou,

Ah, OK, then the DB Multi-Record Loader needs to have a WHERE entry like
`column_name` = '<?php echo $form->data['drop_down_name']; ?>'


Bob
mathmathou 07 Oct, 2013
Thanks GreayHead, that did the trick !! I was close but... not that close in fact 😶

Again, thanks for your help and that great tool of yours.

Math
This topic is locked and no more replies can be posted.