Hi I was wondering if someone could help me with a code for my website? Basically what I want to do is have a drop down list that is essentially a matrix in the sense that picking one option leads to another and eventually you can narrow down the results and find what you're looking for.

for example if i was searching for cars:

what type of car: honda, ford, etc
what colour: red, blue, green etc
what year: 1999,2000 etc
price: under 5000, etc

and eventually these choices would lead to different results based on what the users input was. If I am posting in the wrong section I am sorry as I am new here and this seemed a good fit...thanks I appreciate any help I can get as I am a novice who has a website!

also if this is not an HTML menu I am looking for please let me know!

Dani AI

Generated

wanted cascading drop‑downs to narrow car choices; correctly pointed out the need to pick an implementation based on where the data lives. Below is a compact, practical plan that works whether the data set is tiny or very large.

For larger data sets expose a small API that accepts current filters and returns both matching rows and the updated allowed values for each filter. Returning allowed values lets the UI disable or hide impossible choices and keeps the selects in sync with the real data. Example response shape:

{
  "results": [{ "id": 123, "make": "Honda", "year": 2000, "price": 4500 }],
  "filters": {
    "make": ["Honda","Ford"],
    "color": ["red","blue"],
    "year": [1999,2000,2001]
  },
  "total": 42
}

On the server use parameterized queries and indexes on columns users filter by. A simple SQL pattern (use your DB client prepared statements) looks like:

SELECT * FROM cars
WHERE (make = ? OR ? IS NULL)
  AND (color = ? OR ? IS NULL)
  AND (year = ? OR ? IS NULL)
ORDER BY price
LIMIT ? OFFSET ?

Practical tips: debounce filter requests to avoid spamming the server; paginate results; return counts so the UI can show "42 matches"; keep an "Any" option that maps to NULL so queries stay simple; validate all input on the server to prevent injection; and update the URL query string so filtered views are bookmarkable. For very small inventories, load a compact JSON once and filter in the browser to keep things simple.

Recommended Answers

All 3 Replies

If all options you are talking about are independent (use them as criteria of search), you should produce and display the result on the server side; otherwise, use JavaScript to narrow the selection down before you let the server side display the result. I still believe that your selections would be quite independent and would be used as criteria in database search...

ok yeah I believe they will all be independent too, do you know where I could get the code to make this work?

Do you have a server to do the work for you? Or where do you save all possible results from user selection? If you have a server with database to handle it, you could simply handle this by passing all value via 'form' tag to the server. Then use server side script/code to compose a database SQL call. After that, you use the result from the call in result display. If you want to do this on client side only, you need to place all results on the page you are showing but hide them from display. Then you could select each of them while user is picking selection. Your information is too vague.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.