• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[solved] Get $this->db->distinct() to work

Hi all,

I'm quite new to code igniter, but so far so good! I only now have a problem which I can't see to solve. Below i'm extracting some data in my model. It works fine, except for the distinct part...

Does anyone know where to place this distinct line, and how to distinct it on the collumn 'name'.

    $Q = $this->db->get('products');

At this moment this extraction works only I still get duplicates with the same name. (so the distinct part is not being done. Looks like it get skipped for some reason)

Many thanks in advance!


Does no-one have any idea? Seems to me like a simple mistake in how to use the code... (I wish i knew what it is Wink)

First you could try to remove the parameter from the distinct method because it doesn't need one, as second option you can try using group_by('name') instead of distinct.

Thnx Xwero! That's all I needed.

Removing the parameter of distinct didn't work, also it should only make sure it doesn't get duplicates of items with the same name, while there can be duplicates in 'image' and 'category_id'.

The other option to use group_by('name') is the solution to my problem. It works perfectly! Have seen this function in the 'user guide' but didn't knew I could use it for this particular problem.

For the onces stumbling upon this topic while searching for a solution for the distinct function, my working end code now looks like;

    $Q = $this->db->get('products');

Again thanks for this simple solution xwero!

I did a check on the web and it seems the distinct keyword disregards the where part of the statement but the mysql documentation says otherwise. I think it will be a mysql version related problem.

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.