Building a Food Recipe website. |
I an very new to codeigniter. And i successfully build a small CMS witch I am using for the base foundation for the website. You can find the working site here:
http://clanguild.bellswebdesign.com/ and the admin is here: http://clanguild.bellswebdesign.com/admin/user/login with a user name: demo@demo.com and password: pass Now for my problem. I need help with the add recipe php page. That one page puts info into 4 tables: recipes database ingredients database directions database measurements database and my database model Now I have put thinking about this long time and I can not get it. The problem I will run into later is. Every user will have its own database with only there recipes. I was thinking of putting the user_id on every recipe. Is this way I should do it or is there a better why. Please i may have more problems later to. And this website is my first project and I will have more coming cuz I am trying to build a web company so may have room for more staff but much later. Any help is good. I attach some of my work. [attachment=152]
You need the users ID added to each entry in the recipes table, so that you know what recipes belong to what user.
But you do not need to have the users ID in the other tables though, they only need the "parents" id. That would mean recipes ID for ingredients & direction tables. And measurements only need the ingredients ID. In a try to describe the relations.
I would do the setup this way Users id name password Recipes id users_id name image rating Ingredients id recipes_id name sive Directions id recipes_id direction prep_time cook_time Measurements id ingredients_id name I would also recommend setting up relations so that if a recipe is deleted from the database, all entries in ingredients, directions and measurements that belong to that recipe get deleted from the database automatically. Here is some information on that.
Any thoughts on my problem with the recipe page. I need help with the model. Should I have a model for every table or can I do it all one. On one page I'm trying to add to four different tables. The recipe table, ingredients table, descriptions table and the measurement table.
(04-01-2015, 06:56 PM)bellsdesign Wrote: Any thoughts on my problem with the recipe page. I need help with the model. Should I have a model for every table or can I do it all one. On one page I'm trying to add to four different tables. The recipe table, ingredients table, descriptions table and the measurement table. If every user will have their own recipies, then sure, each recipe should have the id of the user that owns it. As far as a model for every table, no, you can certainly include more than one model per table. In the case of users, you would have one model and one table, users. That's because when you add users or modify their information, you only need to access the users table. But if you're adding or editing recipies, or anything that involves related tables, then you include all those tables in one model. I don't mean to make your design more complicated, but if you have ingredients linked to a recipe, then you're going to have to duplicate rows in your ingredients table for common ingredients like salt, sugar, onions, tomatoes, etc. You need a third table between recipes and ingredients, like this (skeletal). RECIPES id user_id name QUANTITIES id recipe_id -- links to recipes table ingredient_id -- links to ingredients table quantity INGREDIENTS id name If someone removes a recipe, you delete the recipe row and the quantity row, but you leave the ingredients table alone because other recipes use it too. If you're not familiar with the subject, google for "database normal form." There should be some good tutorials out there.
Hey, don't work without a PHP debugger. Several free IDEs have this features built in. Two are NetBeans and CodeLobster. Without a debugger, it's like you're driving with a blindfold on -- you are going to crash!
|
Welcome Guest, Not a member yet? Register Sign In |