Converting Data Attribute to Table Attribute Part I

Converting Data Attribute to Table Attribute Part I


WHAT IS THIS ALL ABOUT?

Sometimes there is a need to create dynamic tables or views with variable field structure; In this post, I'm going to explain how to convert data attributes into table attributes; data attributes are values in table field;

TABLES STRUCTURE WE HAVE

Users table

id Username Firstname lastname
1000 Jkhar Jasim Khar
2000 Lmoor Leda Moor

User_attribute table

id attribute_name attribute_value user_id
1 job title Software Engineer 1000
2 Salary $55000 1000
3 Department R&D 1000
4 job title System Administrator 2000
5 Salary $60000 2000
6 Department On Demand 2000

THE RESULT
new_user_attribute table

id username firstname lastname job_title Salary department
1000 Jkhar Jasim Khar Software Engineer $55000 R&D
2000 Lmoor Leda Moor System Administrator $60000 On Demand

In in the next post Converting Data Attribute to Table Attribute Part II, I will demonstrate in code how all of that can be done; code is written for MySQL users.

Have any Question or Comment?

Leave a Reply

Your email address will not be published. Required fields are marked *