jowen  
          
              
                September 6, 2011,  4:25am
               
              1 
           
         
        
          Hi guy,
i will show the location list without duplication info inside. How to do it?? How to distinct the location list with findAll()?
    public function getLocationOptions()
    {
        return
        CHtml::listData(company::model()->findAll(), 'id', 'location');
    }
Pls help. Thx
         
        
           
         
            
       
      
        
          
          
            mukeshsoni  
          
              
                September 6, 2011,  5:44am
               
              2 
           
         
        
          
 jowen:
 
Hi guy,
i will show the location list without duplication info inside. How to do it?? How to distinct the location list with findAll()?
    public function getLocationOptions()
    {
        return
        CHtml::listData(company::model()->findAll(), 'id', 'location');
    }
Pls help. Thx
 
 
Maybe there is a way you can specify it in findAll. But you can surely use CDbCriteria
$criteria = new CDbCriteria();
$criteria->distinct = true;
CHtml::listData(company::model()->findAll($criteria), 'id', 'location');
 
        
           
         
            
       
      
        
        
          You were almost there:
CHtml::listData(company::model()->findAll(array('select'=>'id, location', 'group'=>'location'))), 'id', 'location');
for more info look at:
Working withg AR
Yii find*()
Yii CDbCriteria
         
        
           
         
            
       
      
        
        
          
Maybe there is a way you can specify it in findAll. But you can surely use CDbCriteria
$criteria = new CDbCriteria();
$criteria->distinct = true;
CHtml::listData(company::model()->findAll($criteria), 'id', 'location');
 
 
Mukesh, SELECT DISTINCT only filters exactly identical datasets. If you want to filter a dataset by a single field You need to group the dataset by that field.
         
        
           
         
            
       
      
        
          
          
            jowen  
          
              
                September 6, 2011,  6:17am
               
              5 
           
         
        
          Thank Kiriakos Kappa Krastillis and Mukesh for suggestion. Kiriakos’s solution work every well. Thank man. I learn new thing today. XD
         
        
           
         
            
       
      
        
          
          
            mukeshsoni  
          
              
                September 6, 2011, 11:22am
               
              6 
           
         
        
          
 Kiriakos Kappa Krastillis:
 
Mukesh, SELECT DISTINCT only filters exactly identical datasets. If you want to filter a dataset by a single field You need to group the dataset by that field.
 
 
Thanks for the correction. don’t know what was i thinking <feeling stupid>