简体   繁体   中英

i want a array which will be going to store the login user id with the exisiting id's

Updating the array without updating the existing record in it.

  • I am having a users table and course table. In course table i have user_id and i want this user_id column data to be in array. So i could define that this course has been taken by how many users.

I had Already tried it bu using insert method but it's not working and here the problem is we have update as well as create. So i am confused about how to get rid out of it.

For this how to update the array without updating existing id's in array.

Thanks in Advance!!

and i want this user_id column data to be in array

Don't do that. You'll only be making things more difficult for yourself. The problem you're currently experiencing and asking about is just the tip of the iceberg.

Instead, create another table which has a foreign key to the users and a foreign key to the courses. Maybe call it something like usercourses :

usercourses
--------------------
id        | INT PK AUTOINCREMENT
user_id   | INT FK
course_id | INT FK

Conceptually, each record in that table represents an association between a users and a course . Each association is trackable and editable independently. This is called a "many to many relationship" between users and course .

As the complexity of the data grows, in cases like this the association itself can easily become its own entity. For example, in the domain of Students and Courses consider an entity called a Registration. It is the association between a Student and a Course, but also carries its own business data. The dates of registration, the student's grade perhaps, etc. Storing all of this in your array and stuffing it into a single string field would be problematic to say the least.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM