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

  • Home
  • SEARCH
  • 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 6338679
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T19:29:42+00:00 2026-05-24T19:29:42+00:00

The following code is issuing the following error message: A Database Error Occurred Error

  • 0

The following code is issuing the following error message:

A Database Error Occurred
Error Number: 1066
Not unique table/alias: 'users'

SELECT * FROM (`users`, `users`) JOIN `user_profiles` ON `users`.`id` = `user_profiles`.`user_id`

Filename: /home/xtremer/public_html/kowmanager/models/cpanel/dashboard.php

Line Number: 38

Here is my code:

class Dashboard extends CI_Model {
  private $table_name = 'users'; // user accounts
  private $profile_table_name = 'user_profiles'; // user profiles

  function __construct() {
    parent::__construct();
    $ci =& get_instance();
    $this->table_name = $ci->config->item('db_table_prefix', 'tank_auth').$this->table_name;
    $this->profile_table_name = $ci->config->item('db_table_prefix', 'tank_auth').$this->profile_table_name;
  }

 /**
  * Get user info by Id
  *
  * @param int
  * @param bool
  * @return object
  */
  function get_user_info($id) {
    $this->db->select('*');
    $this->db->from('users');
    $this->db->join('user_profiles', 'users.id = user_profiles.user_id');

    $query = $this->db->get($this->table_name);
    if ($query->num_rows() == 1) {
      return $data = $query->row();  
    }  else {
     return NULL;  
    }
  }
}

EDIT: I know have this for my function and changed it because after looking at it I didn’t need the extra table. I have an array ($data) of values being sent to my header but can I get away with sending it to the build that way it sends the array to all the partials.

function get_user_info($id)
{
    $this->db->select('*');
    $this->db->from('users');
    $this->db->where('users.id', $id);

    $query = $this->db->get();

    if ($query->num_rows() == 1) 
    {
        return $data = $query->row();    
    }
    else 
    {
        return NULL;    
    }

}   

And this is from my controller I updated:

function index()
{
    $id = $this->tank_auth->get_user_id();

    $data = $this->Dashboard->get_user_info($id);
    print_r($data);
    $this->template->set_layout('cpanel')->enable_parser(false);
    $this->template->set_partial('header', 'partials/header', $data);  
    $this->template->set_partial('sidebar', 'partials/sidebar');  
    $this->template->set_partial('content', 'partials/content');      
    $this->template->set_partial('footer', 'partials/footer');
    $this->template->build('/cpanel/index');
}
  • 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-05-24T19:29:44+00:00Added an answer on May 24, 2026 at 7:29 pm

    The problem is this:

    SELECT * FROM (users, users)
    

    I assume you’re trying to join the table to itself, but you can’t do that without giving aliases to the tables, otherwise the database doesn’t know which side of the join you’re referring to when you reference fields from it.

    Try this:

    SELECT * 
    FROM users u1, users u2 
    JOIN user_profiles ON u1.id = user_profiles.user_id
    

    Update:

    My above answer was written based on the error message, but I didn’t notice the code link (I’ve since added the code to be inline with the question).

    I’m not overly familiar with CI, but I have a feeling your problem lies in these three lines:

    1. private $table_name = 'users';
    2. $this->db->from('users');
    3. $query = $this->db->get($this->table_name);

    In line 3, you’re explicitly getting $this->table_name which points to the users table as shown in line 1). However, by explicitly setting a from table, also pointed to users, in line 2, I think you’re accidentally setting up a join between two tables. Since these two tables are both the same, and neither is aliased, it is resulting in an error. Try removing the $this->db->from('users'); line and seeing if that resolves the issue.

    Update 2:

    I’ve been reading the CodeIgniter user guide, and it seems you don’t need to specify anything as a parameter to $this->db->get() when you’re using building a query using methods like from(). I’d suggest just changing this line:

    $query = $this->db->get($this->table_name);
    

    to this:

    $query = $this->db->get();
    

    See this page for details.

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

Sidebar

Related Questions

Following code fails with a error message : t.cpp: In function `void test()': t.cpp:35:
The following code works great in IE, but not in FF or Safari. I
Following code does compile whereas name aNumber is not declared before use. class A
Following code is an example of text placed into a textarea from a database.
Following code is giving compilation error in visual studio 2009. #include <iterator> #include <vector>
Following code work for visualizing a molecule on a JPanel except it does not
Following code does NOT work, but it expresses well what I wish to do.
following code work fine but 1 error $(document).ready( function() { $(#myCheckboxes input[type='checkbox']).change(function() { var
Following code does compile in gcc 4.5 but it is not being compiled in
Following code for passing an object to event handler is not working: $('a.another').live('click', function(e,

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.