This topic is locked

prevent the user from repeat selecting the same value in other lists

3/17/2023 9:21:41 PM
PHPRunner General questions
A
Abbas author

I have 10 dropdown boxes (wish1, wish2, wish3 ...) all dropdown boxs have same items

I want to prevent the user from repeat selecting the same value in other lists

If the user selects a value in one of the dropdown box, he shouldn't choose it in another dropdown boxes

D
DRCR Dev 3/29/2023

Hi

You need a helper table depending on how many wishes you have.

Lets say you have 4 wishes, you would need 4 columns.

Then you have to map every single combination so that each row represents a possibility. In the drop down options, you would reference the helper table and have it use exclusive values only.

COL1 COL2 COL3 COL4
WISH1 WISH2 WISH3 WISH4
WISH1 WISH3 WISH4 WISH2
WISH1 WISH4 WISH2 WISH3

repeat for every combination.

You'd setup a chain of col2 depends on col1, col3 depends on col1 and col2, col4 depends on col1, col2 and col3

If you have a lot of wishes, the table can be quite big.

I had to do this once before for age ranges and the table had about 4000 lines.

If possible try and use a check box list, but I imagine you want to prioritise the wishes. With a checkbox list with VARCHAR options there is some neat code for playing with the data in this forum that I used in my last 2 projects.

There might be a way of using helper tables to simplify the process but I haven't had enough caffiene to imagine the steps needed yet.

Good luck. The project sounds interesting - wishes and all :-)