Retrieve data from database

Hi there, I am new to Yii framework, I have a problem here:

I have 2 database tables and I need to retrieve the data into the register form’s drop down menu. The data needed to be compared within 2 tables and I have already done the query part, here is the question:

How am I using the built in Yii model or classes for my query and return the array result?


Welcome to the world of ActiveRecord.

Active record is described in the definitive guide under the header "Working with databases":

  • Active Record: this describes the basics

  • Relational active record: link related tables.

If you just want retrieve how to load data from database,

that top guy andy_s teach me this :

Yii::import('zii.widgets.CMenu', true);

class ActiveMenu extends CMenu


    public function init()


        // Here we define query conditions.

        $criteria = new CDbCriteria;

        $criteria->condition = '`status` = 1';

        $criteria->order = '`position` ASC';

        $items = MenuModel::model()->findAll($criteria);

        foreach ($items as $item)

            $this->items[] = array('label'=>$item->label, 'url'=>$item->url);



See this topic…

if you want to compare two query result use array_diff (see php manual)

if you just want to build some menu, try this extension : JQuerySlideTopMenu

sorry if not very help. :mellow:

Dear guys, thanks for your reply.

Basically, both tables have the relationship; for example,

Table 1:

ID EmployeeName DepartmentID

1 Joe 1

2 John 2

3 Mike 2

Table 2:

DeptID DeptName Salary

1 IT 5000

2 HR 4000

3 ACCT 3000

In the drop down menu, I would like to show the below content by using query:




I have done the query but I don’t know how to insert my query into the Yii class or Yii framework.