thebadbad Posted August 22, 2009 Share Posted August 22, 2009 I'm creating an online cookbook, and need some advice on how to structure the database tables. Here's my idea: I'll need a recipes table containing the titles of the recipes, cooking procedure and corresponding recipe IDs. Then an ingredients table containing all ingredients and corresponding ingredient IDs. And lastly, one or several tables linking ingredients (via the ingredient IDs) with the recipes (via the recipe IDs), including the amount of each ingredient that goes into each recipe, along with a unit (e.g. litre or tablespoons). The structures of the first two tables are straight forward, but I need some advice on how to structure the last one(s) linking recipes with ingredients. The only solution I can think of includes storing of delimited strings, which is inefficient and bad practice I'm sure. Thanks in advance! Quote Link to comment https://forums.phpfreaks.com/topic/171456-cookbook-table-structure/ Share on other sites More sharing options...
thebadbad Posted August 22, 2009 Author Share Posted August 22, 2009 Came up with this reasonable solution for the table that links the recipes with the ingredients: +-----------+---------------+--------+----------+ | recipe_id | ingredient_id | amount | unit | +-----------+---------------+--------+----------+ | 1 | 1 | 3 | litre | | 1 | 2 | 1 | teaspoon | +-----------+---------------+--------+----------+ But I would still like some feedback or suggestions for improving the structure. As part of the site, I'd like to include a feature where you can tell which ingredients you have, and get a list back of meals to make from those. The above structure wouldn't be very efficient when dealing with that, right? Quote Link to comment https://forums.phpfreaks.com/topic/171456-cookbook-table-structure/#findComment-904178 Share on other sites More sharing options...
fenway Posted August 25, 2009 Share Posted August 25, 2009 As part of the site, I'd like to include a feature where you can tell which ingredients you have, and get a list back of meals to make from those. The above structure wouldn't be very efficient when dealing with that, right? Why not... simply compare a list of recipes with total # of ingredients to the number of ingredients available. Quote Link to comment https://forums.phpfreaks.com/topic/171456-cookbook-table-structure/#findComment-905931 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.