Yii Framework Forum: Call For Unique Records - Yii Framework Forum

Jump to content

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

Call For Unique Records Rate Topic: -----

#1 User is offline   roadrunner 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 69
  • Joined: 21-June 12

Posted 27 January 2013 - 11:22 PM

Hi need help!
in my table i have
dept
value
businesses
engineering
engineering
agriculture
businesses

now here's the situation I want it to display them without duplication! it should show 1 bus., 1 engr., and 1 agriculture.

//my view code
	
 $this->beginWidget('zii.widgets.CPortlet', array(
			'title'=>'Dept',
		));
			$listpage=dept::model()->findAll();
        foreach ($listpage as $listpage){
		 
            $models2 = dept::model()->findBypk($listpage->id);
			 
            $mysidebar[] = $models2->getAlldept();        
       
		}
		$this->widget('zii.widgets.CMenu',array(
			'items'=>$mysidebar,	
'htmlOptions'=>array('class'=>'operations'),			
		));



public function getAlldept() {
  
	  
   $sidebar =array('label'=>$this->dept_user, 'url'=>array('/dept/index', 'pid'=>$this->dept_user));
    return $sidebar;
 
}

0

#2 User is offline   Liam Carter 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 18
  • Joined: 30-August 12

Posted 28 January 2013 - 03:11 PM

Howdy.

I will have a stab at this, though there isn't much to go on.

I believe you are trying just to get the last 1 of each dept from your database.
If so then add a group by to the findAll command

$listpage=dept::model()->findAll(array('group'=>'dept'));


This should just return one row per different dept.

Regards

Liam
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