customize a sql query results to CDetailView

i am trying to customize a sql query results to CDetailView as shown onthis link.and it gives this error

Error 500

Undefined offset: 0

any assistance to understand this i shall appreciate.

my controller codes




public function actionView($id)

	{

		//second option

		$q="Select family.familyID,concat(employee.lastName,' ',employee.firstName,' ',employee.secondName),family.WifeOrHusbandName,family.sonsName

				,family.daughtersName,family.familyAddress from family JOIN employee ON family.employeeID=employee.employeeID where family.familyID=".$id;

		$sqlProvider = new CSqlDataProvider($q);

		$sqlProvider = $sqlProvider->getData();

		$sqlData = $sqlProvider[0];

		

		$this->render('view',array(

				'model'=>$sqlData,

		));

		

	}

view codes.


$this->widget('zii.widgets.CDetailView', array(

		'data' => $model,

));



It’s possible there are no rows resulting from your query… in that case


$sqlProvider->getData;

returns an empty array.

Also it’s not a good practice to overwrite a variable with a different type of data like you are doing here


$sqlProvider = $sqlProvider->getData();

at first $sqlProvider is an CSqlDataProvider [size=“2”]object and after this assignment above it’s an array. It’s better to use a new variable here.[/size]

thanks alot,i have tried the print_r($sqlData); it has a resulting row

Array ( [familyID] => 5 [concat(employee.lastName,’ ‘,employee.firstName,’ ',employee.secondName)] => Masige Kelvin M [WifeOrHusbandName] => mary kenchi [sonsName] => jonathan kkkkk [daughtersName] => lllllll [familyAddress] => arerewr )

however let me try changing variable names

still the problem exists




$q="Select family.familyID,concat(employee.lastName,' ',employee.firstName,' ',employee.secondName),family.WifeOrHusbandName,family.sonsName

				,family.daughtersName,family.familyAddress from family JOIN employee ON family.employeeID=employee.employeeID where family.familyID=".$id;

		$sqldata= new CSqlDataProvider($q);

		$dt = $sqldata->getData();

		$familyData = $dt[0];

		//print_r($familyData); exit;

		

		

		$this->render('view',array(

				'model'=>$familyData,

		));



So the data is there… and it seems the error does not fire on the line $familyDta = $dt[0];

[size="2"]Try to find the line where the error happens?[/size]

thanks alot i got it the error was was not firing at $dt[0]; i fixed it,now it throws this

CException

The attribute must be specified in the format of "Name:Type:Label", where "Type" and "Label" are optional.

When you solve a problem it’s nice to post what was the problem and how you solved it, this way other users in the future can benefit from reading this thread if they have a similar problem.

The exception you are getting now is related to CGridView, check the documentation, check some examples on how it’s used and see if you can solve it.

If you still have a problem open a new post for that error because it’s not related to this discussion.

ok i got u the problem was originating from $model[0];




<?php

$this->breadcrumbs=array(

	'Families'=>array('index'),

 	$model[0],

);


$this->menu=array(

	array('label'=>'List Family', 'url'=>array('index')),

	array('label'=>'Update Family', 'url'=>array('update', 'id'=>[s]$model[0][/s])),

	array('label'=>'Delete Family', 'url'=>'#', 'linkOptions'=>array('submit'=>array('delete','id'=>$model[0]),'confirm'=>'Are you sure you want to delete this item?')),

	array('label'=>'Manage Family', 'url'=>array('admin')),

);

?>


<h1>View Family #<?php echo $model[0]; ?></h1>


<?php 

//second option

$this->widget('zii.widgets.CDetailView', array(

		'data' => $model,

));


?>

?>



thanks alot @Maurizio Domba Cerin