简体   繁体   English

我想要一个数组,它将存储登录用户 ID 和现有 ID

[英]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.在课程表中,我有 user_id,我希望这个 user_id 列数据在数组中。 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.为此,如何在不更新数组中现有 id 的情况下更新数组。

Thanks in Advance!!提前致谢!!

and i want this user_id column data to be in array我希望这个 user_id 列数据在数组中

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之类的东西:

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 .从概念上讲,该表中的每条记录都表示userscourse之间的关联。 Each association is trackable and editable independently.每个关联都是可独立跟踪和编辑的。 This is called a "many to many relationship" between users and course .这被称为userscourse之间的“多对多关系”

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.注册日期,可能是学生的成绩等。将所有这些存储在您的数组中并将其填充到单个字符串字段中至少可以说是有问题的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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