I have a basic data structure for storing recipes. It consists of three tables as below:
Table 1 - Recipes (recipe_id, recipe_name)
Table 2 - Ingredients (ingredient_id, ingredient_name)
Table 3 - Recipe_Ingredients (recipe_id, ingredient_id)
I have come across a problem when adding a new recipe and would like to know the best practice for inserting.
Currently, on submitting the form I insert into the Recipes table, the recipe_id is auto generated. I then insert into the Ingredients table, again the ingredient_id is auto generated. The third step on submit is to then insert into the Recipe_Ingredients table, but how do I get the values of the recipe and ingredient ids that have just been created in order to insert them into the Recipe_Ingredients table?
I currently have separate PHP functions to insert into the Recipes and Ingredients tables.
解决方案
You have to get the inserted id value after each insert operation.
The function to get the last insert id is: mysql_insert_id()
因篇幅问题不能全部显示,请点此查看更多更全内容
Copyright © 2019- banwoyixia.com 版权所有 湘ICP备2023022004号-1
违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com
本站由北京市万商天勤律师事务所王兴未律师提供法律服务