How To Solve Page Loading Problem


I create a form contain payment_no,payment_date,student_id and so many in main model page. payment_no,payment_date are coming from payment table references with foreign key. Now create a user defined function set_student_details($id) for displaying list details in view page as follows,

public static function set_student_details($id)


		$sqlProvider = new CSqlDataProvider('select Student_Name from m_student where student_ID='.$id);

		$sqlProvider = $sqlProvider->getData();

		$sqlData =  $sqlProvider[0];



When submit a form its values are stored in database and page converted to view page. Now my problem is when URL change(folder_name/index to folder_name/view&id=$id) then it shows

Undefined offset: 0 

Stack Trace 01


C:\xampp\htdocs\new_tms_demo\protected\views\main\view.php(which is mention through color="#FF0000"): Main::set_student_details("$id")






            [color="#FF0000"]'value' => $model->set_student_details($model->Student_ID),[/color]


Stack Trace 02

C:\xampp\htdocs\new_tms_demo\protected\controllers\MainController.php(which is mention through color="#FF0000"): CController->render("view", array("model" => Main))


     public function actionView($id)






Please tell me how to solve this problem.


In this line

$sqlData =  $sqlProvider[0];

what is [0]?

can you post the some code so i can undestand ?

Hello Ankit Modi,

In my post

$sqlData =  $sqlProvider[0];

means when write var_dump($sqlProvider) you will see an array with in an array (array(array(value)). For this reason write $sqlProvider[0], i.e. 0th position of $sqlProvider.

Hope I can clear your query.

ok got it can you post the array what should be generated?

Hello You are getting this issue when there is no array data in $sqlProvider or it is not an array.

So you need to check that any value exist via is_array() or any other function in php.

For Fetching data , you may also use :

    $query = 'select Student_Name from m_student where student_ID='.$id;

    $command = Yii::app()->db_name->createCommand($query); //DB Name defined in configuration

    $sqlProvider = $command->queryAll(); // or queryRow()

    if(is_array($sqlProvider) && $sqlProvider[0] != '')

          echo 'value exists & process further';