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,
));
}
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]
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.