nicinin
(Nicinin95143)
May 18, 2010, 5:25am
1
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?
Thanks.
Onman
(O Rijkers)
May 18, 2010, 9:33am
2
Welcome to the world of ActiveRecord.
Active record is described in the definitive guide under the header "Working with databases":
xicath
(Xicath)
May 19, 2010, 3:36am
3
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.
nicinin
(Nicinin95143)
May 19, 2010, 7:04am
4
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:
Joe-IT-5000
John-HR-4000
Mike-HR-4000
I have done the query but I don’t know how to insert my query into the Yii class or Yii framework.
Thanks.
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.