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 7867753
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T00:47:35+00:00 2026-06-03T00:47:35+00:00

I’m trying to create a system more dynamic for my users, implementing a way

  • 0

I’m trying to create a system more dynamic for my users, implementing a way of they create each necessary information when they needed. (Sorry if my english is weak)

First, I have a table named User, like this:

User:

id   |   name   |    login   |     password

1    |   Rose   |  rose.120  |     897763
2    |   John   |  john.red  |     120347
3    |   Mark   |  mark.foo  |     385598

and the other table with some info of each user:

User_info:

id  |  user_id  |  info_name      |   value          |  required  |  order

6   |   1       | Telephone       |  555-4083        |   yes      |   2 
7   |   1       | Email           |  rose.120@g.com  |   yes      |   1 
8   |   1       | Another E-mail  |  rose.mg@fc.com  |   no       |   3 

When I get this values from the database, how make an efficient way to set a PHP Object, or an Array of this values.
I tried to make a mysql_query and with this result make a loop in the Object, and for any Row make a WHERE clause to the user id. (I’m using CodeIgniter)

    if( $user != false ) $this->getUser();
    foreach( $this->user->result() as $row ) {
        $this->db->where('user_id', $row->id);
    }
    $this->db->from('user_info');
     ...

and when I have this Object I will need to put the User_info rows in the User Object. Correct?
I’m just curious if this is a good way of doing this, or I’m in the wrong way.
I hope that’s clear.
Thanks.

  • 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-03T00:47:36+00:00Added an answer on June 3, 2026 at 12:47 am

    Basically, yes. You could set up your model to define a method for retrieving information from both your user_info and user tables, however. Something along these lines:

    // in user_model.php
    function get_user_with_info() {
      $user = $this->getUser();
      $user['info'] = $this->db->where('user_id', $row->id)->from('user_info')->row();
    
      return $user;
    }
    

    If you are planning to make this query often, you will quickly run into the N+1 problem. A better option in Codeigniter might be to use a table join in a get_users function:

    function get_users() {
      $this->db->select('*')
      $this->db->from('user');
      $this->db->join('user_info', 'user.id = user_info.user_id');
    
      $results = $this->db->result();
      $users = [];
      foreach ($results as $result) {
        $user_id = $result['user_id'];
        if (!isset($users[$user_id])) {
          $users[$user_id] = array(
            'id' => $user_id,
            'info' => array(
              // add info fields from first result
            )
          );
        } else {
          $users[$user_id]['info'][] = array( 
            // add additional info fields
          );
        }
      }
      return $users;
    }
    

    You will need to adjust the specifics, but hopefully this gives somewhere to start.

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

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am trying to render a haml file in a javascript response like so:
In my XML file chapters tag has more chapter tag.i need to display chapters
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka

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.