Categories and Subcategories do not update - PHP7

Asked

Viewed 75 times

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:

inserir a descrição da imagem aqui

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.

  • 1

    Can your system have more subcategory levels? Or will it always be Category->Subcategory?

  • Diego Machado, this system will only have Category and subcategory.

  • 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.

  • 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.

  • 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..

  • 1

    Tell me if you have any difficulty with any of the points I have mentioned

  • 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

Show 2 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.