The database has a table with id and followers columns. There are 3 users respectively with id = 1, 2, 3 and empty fields in the followers column. I want to make it so that when adding a new line (with id 4, 5 values id 4, 5 , etc.) to the followers column, the user with id 1 inserts these id into the field (in 1,2,3,4,5,6,7 format etc.). Is it possible to implement this directly in phpmyadmin ?
- you can implement. only phpmyadmin has nothing to do with it. this is done by triggers. And to do this, in the form that you want, should not be in any case. In the database you can not store values separated by commas. Well, that is Of course you can, but then working with data in this format is wildly difficult. ru.stackoverflow.com/… - Mike
- onehabrahabr.ru/post/254773 pay attention to the first normal form, your data already violate it. but for good it is necessary that the database be 5th normal form, then it will be easy to work with it in SQL - Mike
- It would be more correct to do this: remove the column with the name "folowers" from the "User" table and add the table "folower", which will contain the idUser field (this is the id of the user that folower has subscribed to). - Andrei Khotko
|
1 answer
This should be implemented at the code level:
- When inserting we get the id of the inserted record.
- Get previous data (followers list) from user (id 1)
- Add a new ID for them
- Next, do UPDATE on the line with this user (id 1)
PHPMyAdmin is a MySQL management tool. If we are talking about whether it can be implemented at the MySQL level, then theoretically it is possible through triggers, but it will turn out in one place. Normally this is all done through your own code.
|