Retrieve Data From Database

can any one help me to retrieve data from database and display it.

in my database I have a table called “menu” which has ‘menu_id’ and ‘menu_label’. I want to retrieve these menu label from database and display on my home page… But I don’t know how to do it. can any one help me…

Thanks, :)


$sql = "your query here.";

 $dataReader =  Yii::app()->db->createCommand($sql)->query();


        while(($row = $dataReader->read())!==false) {

            $data[] = $row;

        }

print_r($data);

I suppose that U have model for this menu table. If so than U can do it like:

$menus = Menu::model()->findAll();

foreach($menus as $menu) {

echo $menu->menu_label;

}

This approach will also allow U to use any relation and stuff

I’m very new for yii. you will feel this is a silly question. I don’t know where to add this one… can you help me…

Hi there,

In my opinion, it’s better to learn about yii and its MVC archtecture (how the model, controller and view interact between each other) the. You’ll find your own solution :)

Yeah. Now i also think so… :)