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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:22:38+00:00 2026-06-13T10:22:38+00:00

Ok just to keep this simple I need to loop through the DISTINCT results

  • 0

Ok just to keep this simple I need to loop through the DISTINCT results of each column in a this table called PRINTS Now here is the strange part …

$this->db->distinct();
$this->db->select('PRINTS.COLOR');
$q = $this->db->get('PRINTS');
return $q->result();

Ok COLOR is a COL in the table AS IS SIZE and PAPER — Ok get ready because this is where it gets strange…

If I do $this->db->select('PRINTS.SIZE'); I am able to loop through the DISTINCT values for SIZE in the table.

HOWEVER

If I do $this->db->select('COLOR'); I get ERROR: A Database Error Occurred / Error Number: 1054 /
Unknown column 'COLOR' in 'field list'

Same thing happens for PAPER too — It seems that only SIZE works as it should. According to CODEIGNITER DOCS, I Need to do: $this->db->select('COLOR, PAPER, SIZE'); But I’m getting an unknown COL error. Spelling is correct. Can anyone shed light on this? What is going on? TY

  • 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-13T10:22:39+00:00Added an answer on June 13, 2026 at 10:22 am

    If you want distinct rows of only each type, you must only use those particular columns individually.

    $this->db->distinct();
    $this->db->select('COLOR');
    $q = $this->db->get('PRINTS');
    $q_color = $q->result();
    
    $this->db->distinct();
    $this->db->select('SIZE');
    $q = $this->db->get('PRINTS');
    $q_size = $q->result();
    
    $this->db->distinct();
    $this->db->select('PAPER');
    $q = $this->db->get('PRINTS');
    $q_paper = $q->result();
    

    As @Rocket Hazmat pointed out, if you have any mixed results they will be treated as distinct rows. My suggestion would be to a) create additional tables to hold these values (preferred), or b) to modify the table columns with the distinct values available.

    A sample COLORS table would be like:

    Colors
    id    | name
    ----------------------
    1     | red
    2     | blue
    3     | green
    

    Then the query for this is simple to get all the colors available:

    $q = $this->db->get('COLORS');
    

    Since you mentioned this was being imported from a CSV file I would say you could perform the necessary processing after you have imported the CSV to pick up the distinct values, like above, then put them in the COLORS table.

    Lastly, I think the best approach is to do some simple normalization once you get the data in order to better query it, and also improve the performance of your app.

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

Sidebar

Related Questions

I am sure this is relatively simple, I just keep running into brick walls.
Well, just to keep it simple: I have a webform. On it a button
I will try to keep this as simple as possible. Basically I have a
I am NOT looking for a plug-in, just need simple jQuery function with regexp.
I need to loop over a list of objects, comparing them like this: 0
I'm just getting started with MySql and need to run simple queries on the
I'll keep this short and sweet, because I'm sure it is something simple that
Maybe I should just keep my mouth shut and move forward, but something tells
Just to keep my sanity, I'm telling Spring to barf on circular references: _context
Just wondering for user permission check, Should you keep the permission in the session

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.