الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

insert into two table

مغلق
بدأه جراح فلسطين في 24 يوليو 2006 · 1 رد · 1,561 مشاهدة · في قواعد بيانات MySQL
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

I have two tables in my database (department, employee)

-department table has three fields (seq, name, place).

-employee table has three fields too (seq, dept_seq, title).

-there are relation between two tables (seq is a primary key in "department" and foreign key in "Employee" as dept_seq).

- I want to insert in the two tables using this code:

$sql="insert into department select ifnull(max(seq),0)1,'".$_REQUEST['name']."','".$_REQUEST['place']."' from department";

mysql_query($sql) or die(mysql_error());

$sql2="insert into employee select

ifnull(max(seq),0)1,XXXXXXXXX,'".$_REQUEST['title']."' from employee";

now XXXXXXXXX is seq value that i wont take from department table but i dont now how i can insert this value into employee table

any suggestion???

تم تعديل هذه المشاركة بواسطة جراح فلسطين في 24 يوليو 2006 في 11:49

#2

You might consider adding another field to department, DATETIME, which then you will fetch the id using it.

Also you should always have a unique auto increment id in your database, like department_id and employer_id

هذا الموضوع مغلق.

مواضيع مشابهة