Yii Framework Forum: how to find distinct values in array? - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

how to find distinct values in array? Rate Topic: -----

#1 User is offline   steffen 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 26
  • Joined: 14-December 09
  • Location:Reutlingen, DE

Posted 08 January 2010 - 08:46 AM

Hey everyone,

I would like to display something like:

Group 1 Header
data for group 1

Group 2 Header
data for group 2


Applying the distinct to the SQL query would leave me without detailed data. So, is there a function in Yii like
$model->getDistinctValues('group')
to extract the distinct values after the query?

As an alternative only a 2nd query comes into my mind :-(
0

#2 User is offline   Horacio Segura 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 535
  • Joined: 11-August 09
  • Location:Argentina

Posted 08 January 2010 - 09:59 AM

View Poststeffen, on 08 January 2010 - 08:46 AM, said:

Hey everyone,

I would like to display something like:

Group 1 Header
data for group 1

Group 2 Header
data for group 2


Applying the distinct to the SQL query would leave me without detailed data. So, is there a function in Yii like
$model->getDistinctValues('group')
to extract the distinct values after the query?

As an alternative only a 2nd query comes into my mind :-(


Sorry. I'm mistaken


for distinct use

$criteria->distinct=true;


for group see
http://www.yiiframew...dpost&pid=33101



This post has been edited by Horacio Segura: 08 January 2010 - 10:03 AM

KISS - Keep It Simple Stupid
ASAP-As Soon As Possible
http://www.yiiframew...oc/cookbook/71/
http://hmsegura.blogspot.com/
0

#3 User is offline   Horacio Segura 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 535
  • Joined: 11-August 09
  • Location:Argentina

Posted 08 January 2010 - 10:09 AM

try this

in the controler

       $models=TableGroup::model()->with('detail')->findAll();


and in the view
<?php foreach($models as $model):?>
...
     <?php foreach($model->detail as $detail):?>
      ...

KISS - Keep It Simple Stupid
ASAP-As Soon As Possible
http://www.yiiframew...oc/cookbook/71/
http://hmsegura.blogspot.com/
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users