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
If you want distinct rows of only each type, you must only use those particular columns individually.
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:
Then the query for this is simple to get all the colors available:
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.