Call For Unique Records

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;

 

}

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