sorenchr Posted October 14, 2008 Share Posted October 14, 2008 Hi, i have a fairly simple table in my DB: Username Tags testuser1 test, bla testuser2 abc, bla2 Im using a php page, which allows the user to add additional tags to their username. So my question is, what mysql query do i use when i want to add additional data to their tags? I only know of UPDATE, but that one replaces all the existing data with the newly entered. To illustrate my question, I, as "testuser1", add the tag "christmas" to my taglist, so that the new table looks like this: Username Tags testuser1 test, bla, christmas testuser2 abc, bla2 Best regards Soren Quote Link to comment https://forums.phpfreaks.com/topic/128408-solved-how-add-additional-data-to-a-cell/ Share on other sites More sharing options...
Daniel0 Posted October 14, 2008 Share Posted October 14, 2008 You shouldn't do it this way. The fact that you are having issues manipulating the data is a testimony to this. What you're looking at is a many-to-many relationship which is made by having a third linking table giving you these tables: users - user_id - username tags - tag_id - name tags_users - tag_id - user_id To get user #568's tags you can do this: SELECT t.name FROM tags_users link INNER JOIN users u ON u.user_id = link.user_id INNER JOIN tags t ON t.tag_id = link.tag_id WHERE u.user_id = 568; And as for your problem, adding a tag to a user is a simple INSERT operation (you'd have to insert a new tag into the tags table as well if it's not a new tag). Quote Link to comment https://forums.phpfreaks.com/topic/128408-solved-how-add-additional-data-to-a-cell/#findComment-665318 Share on other sites More sharing options...
sorenchr Posted October 14, 2008 Author Share Posted October 14, 2008 Thank you, we actually had about data modelling in class today, can't believe the "register" trick went over my head Quote Link to comment https://forums.phpfreaks.com/topic/128408-solved-how-add-additional-data-to-a-cell/#findComment-665322 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.