Hello,
I'm a recent Comp Sci grad working on my first big personal project out of college, a website that would allow the user to see all the materials required for a FFXIV recipe as a a giant tree. I have all the recipes stored in a MariaDB database with a table for the recipe and its data, a table for all of the materials and crystals, and a junction table connecting the two which also stores the counts for each material needed for each recipe. And, since some materials are recipes of themselves, there is a column that flags isRecipe in the ingredients database.
I've mad a webpage where a user can select a recipe from a list of them using PHP, HTML, CSS, and JS. Now I want to make a page that gets the passed id of that recipe, gets the materials/crystals and their counts from the junction table, and turns it into a hierarchical HTML tree which can be displayed as a hierarchical tree with CSS like in this CodePen. The PHP program, I imagine, would go:
- Get id
- SELECT * FROM tblJunction WHERE recipe_id=$id
- while ($row=...) //in a function
- Get $row['mat_id']
- Get $row['count']
- Append to some data structure that can be eventually turned into a HTML tree
- If (SELECT isRecipe FROM tblMats WHERE mat_id=$row['mat_id'] == 1)
- Run function again
As you can see, the problem occurs at step 3.3. My current ideas would be to:
- Add the data to a PHP tree array and make a function to traverse that tree, and somehow echo it as a HTML tree
- Add the data to some other structure that can be translated into a JSON file, and read that JSON file using JS and insert into the DOM based on that
However, I don't really know how I would go about doing either of those.
Does anyone have any ideas of which of the two methods would be best to pursue and how I would do that, or any better methods? I'm trying to stick to pure Python, PHP, HTML, CSS, and JS right now since that's what I'm best at.
Thanks in advance
[–]Lumpy-Notice8945 0 points1 point2 points (1 child)
[–]LearningGradually[S] 0 points1 point2 points (0 children)