0
Starting in programming I am developing an application with PHP
7 and MySql
based on a lost and found site, but with problems in the creation of MENU, where my base is in the picture below:
I can list the categories and subcategories related to it, but clicking on another category does not bring the subcategories because it needs the ID
of the category.
My doubt would be the following, first I would like to click on categories view items from subcategory on the same page, when selecting another category, automatically the subcategory the category will be listed and I saw that I can do this with Ajax
and jQuery
, tested several methods but was unsuccessful.
Would anyone have any similar script or could give me a north? Maybe some example of how to mount this menu.
Can your system have more subcategory levels? Or will it always be Category->Subcategory?
– dm707
Diego Machado, this system will only have Category and subcategory.
– Helder Ferrari
I just need to better understand your question. Would you like to click on a category and display the subcategories relating to it? And also display all products? It was not so clear your question, if you can reformulate it would be easier.
– dm707
Come on, this menu ( categories and subcategories) will be used in a registration form. I would like to list according to the photo above, and this system will only have Category and subcategory.I would like that from the list of categories I can open the subcategories, and if I change the category antrs to submit the form, also update . As follows: I selected cars -> Beetle, in case I change the category to electronics I would like the list of subcategories also to be updated according to the category and on the same page.
– Helder Ferrari
Okay, now I understand what you need. Well, it’s not so simple as a small script solve. I don’t know what codes you already have, but I’ll tell you a little bit about the logic I thought. Basically you would have to have two Hidden Fields in the form, and each time you click on a category update the value of the first Hidden with the category id and the second with the subcategory id (if any). To change category as you said, it would be the same process, create an onclick event for category and call ajax to load the category list. At this same onclick event, Hidden field would be updated, etc..
– dm707
Tell me if you have any difficulty with any of the points I have mentioned
– dm707
Okay, I got the idea, I’m away from the PC now, I’ll read more about Ajax and try to assemble with this logic, I thank you for the help
– Helder Ferrari