I have a list of result-times that athletes have made.
In my CGridview advance search, i want to be able to check a checkbox to only display the best time that every athlete have made.
Checkbox:
Alternative 1: Show all times
Alternative 2: Show only the best time for every athlete
In the "Result" table all the result_times are stored, each result_time has an athlete_id. So I need to limit result_time to 1 for each athlete_id when I check the checkbox somehow.
This is how i did it, need a little help with the search method tho.
public $checkbox;
public function rules()
{
array('..., checkbox', 'safe', 'on'=>'search'),
);
}
public function search()
{
if ($this->checkbox)
{
$criteria->limit = '';
}
// I guess the else-statement isn't nessesary?
}
public $onlyBestTime;
public $bestTime;
…
public function search()
{
$criteria=new CDbCriteria;
if($this->onlyBestTime) {
$criteria->select = 'MIN(resultTime) AS bestTime, t.*';
$criteria->with = array('athlete');
$criteria->group = 'athleteId';
}
…
$dp = new CActiveDataProvider($this, array('criteria'=>$criteria));
// following line to give proper total number of items
// only needed when we use with / group by
$dp->setTotalItemCount(count($this->findAll($criteria)));
return $dp;
}
PS I don’t think limit will work, or I don’t see how.
$dp = new CActiveDataProvider($this, array('criteria'=>$criteria));
// following line to give proper total number of items
// only needed when we use with / group by
$dp->setTotalItemCount(count($this->findAll($criteria)));
return $dp;
with this?
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
CDbCommand failed to execute the SQL statement: SQLSTATE[HY000]: General error: 209 General SQL Server error: Check messages from the SQL Server [209] (severity 16) [(null)]. The SQL statement executed was: SELECT TOP 10 [t].[result_id] AS [t0_c0], [t].[athlete_id] AS [t0_c1], [t].[event_code] AS [t0_c2], [t].[competition_id] AS [t0_c3], [t].[result_time] AS [t0_c4], [t].[result_date] AS [t0_c5], [t].[round_type] AS [t0_c6], [t].[athlete_pos] AS [t0_c7], [t].[team_id] AS [t0_c8], [t].[relay_time] AS [t0_c9], [t].[event_order_number] AS [t0_c10], [t].[split_time] AS [t0_c11], [athlete].