Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8051385
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T07:17:33+00:00 2026-06-05T07:17:33+00:00

I have four classes : User, Attribute, Attribcategory, Attribvalue. and four tables : tbl_user,

  • 0

I have four classes : User, Attribute, Attribcategory, Attribvalue.

and four tables : tbl_user, tbl_attribute, tbl_attribcategory, tbl_attribvalue in the database.

those are the relations between tables :

tbl_user 1 --- n tbl_attribvalue n --- 1 attribute 

(tbl_attribvalue is intermediate table between attribute and user

tbl_attribcategory 1 ---- n tbl_attribute

This is an example :

tbl_user
{id:1, name: Jack}



tbl_category {id:2,label: Career and Education}

tbl_attribute :
{id:1 ,category:2,label:employer , variable: employer}
{id:2 ,category:2,label: High school , variable: high_school}
{id:3 ,category:2,label:college , variable:college}

And as the tbl_attribvalue is an intermediate table between tbl_attribute and tbl_user, we should know the user id , and the attribute id…to know the value of the attribute of the user .

Exemple

tbl_attribvalue {id:1,iduser:1,idattrib:3,value: Harvard University}

This system is used when we have dynamic attributes instead of static labels in the application.

What about classes?

The four classes : User, Attribute, Attribvalue , Attribcategory contain getters and setters and properties each.

I want to return all those attributes, attribcategories and attribvalues for a given user… But I don’t know what method to use exactly, it’s a matter conception.

I have already this code in my controller (In MVC Model) :

$atcdata=array();
$attribcategory=new Attribcategory($atcdata);
$attribcategories=$manager->viewIt($attribcategory,' defined=0 AND ownertype=1');

$manager is a DBManager, it contains a function viewIt($object,$criteria), which then returns an array with the results of the given object, using the given criteria.

so attrib categories is gonna contain all the categories.

But How to use those category information to return the attributes and attribvalues for the given user?

In other words :

I know how to return them , but In terms of performance, I don’t want to use more than two queries to get all the data.

This data example will be displayed as follows for a given user

[attrcategory]
    [attribute] : [attrvalue]
                  [attrvalue]
                  [attrvalue]

Work & Education 
    Employer : Oracle 
               Microsoft

    College : Harvard
    High school : harvard

and the like.

Thank you in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T07:17:35+00:00Added an answer on June 5, 2026 at 7:17 am

    You are doing MVC wrong .. but that’s not the question.

    What you have there, is a ‘Entry-Attribute-Value’ antipattern. It is explored in SQL Antipatterns (in chapter with same title).
    That is what’s causing your problem.

    To get all the results in single query, the best you can do is to aim for something resembling following response structure:

    [attrcategory] , [attribute] , [attrvalue]+[attrvalue]+[attrvalue]
    [attrcategory] , [attribute] , [attrvalue]
    [attrcategory] , [attribute] , [attrvalue]+[attrvalue]+[attrvalue]+[attrvalue]
    

    The query able to produce such result would look approximately like this:

    SELECT 
        AttributeCategories.title AS attrcategory, 
        Attributes.title AS attribute, 
        GROUP_CONCAT(DISTINCT AttribureValues.value
                     ORDER BY AttribureValues.value DESC SEPARATOR '+')
             AS list
    FROM AttribureValues
        LEFT JOIN Attributes USING (attribute_id)
        LEFT JOIN AttributeCategories USING (category_id)
        LEFT JOIN Users USING (user_id)
    WHERE 
        Users.name = 'John Smith'
    GROUP BY Attributes.attribute_id
    

    Then on PHP end of things you will have to explode() values on separator.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have four classes which share some arrangement of four properties. I have currently
I have four tables: Users PrivilegeGroups rdPrivileges LinkPrivilege ----------- ---------------- --------------- --------------- userId(pk) privilegeGroupId(pk)
i have four tables like below in sql server 2008 : TABLE 1 ->
I have four tables: SalesPerson ( personId int ,PersonName nvarchar(20) ..) personAndDistrict ( autoId
I have four classes, let's call S1, S2, S3 and S4. These class are
I have got four classes A , B , C and D . Class
I have a web user control which call some methods of an interface. Four
I have four classes. Class Person , and three more, Student , Professor ,
Say I have four sub-classes of 'Car'. One for each color. I want to
I have four classes. Project Class, Student Class, ProjectFile Class and ProjectFrame JFrame. The

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.