[eluser]srpurdy[/eluser]
Finally managed to figure this out. Breaking this post into multiple posts. Too much code.
Thanks for your help Caio
First I created 2 new model functions
Code:
function champ_drop_import($id, $num)
{
$champ_drop = $this->db
->where('ilr_champ.season_id', $this->uri->segment(6))
->where('ilr_season.season_id', $this->uri->segment(6))
->where('ilr_champ.iracing_cust_id', $id)
->select('
ilr_champ.points,
ilr_champ.pen_pts,
ilr_champ.bonus_pts,
ilr_champ.iracing_cust_id
')
->from('ilr_champ')
->join('ilr_season','ilr_season.season_id = ilr_champ.season_id')
->order_by('ilr_champ.points desc')
->limit($num)
->get();
return $champ_drop;
}
#second function
function get_champ_drop_import()
{
$show_champ = $this->db
//->distinct()
->where('ilr_champ.season_id', $this->uri->segment(6))
->where('ilr_season.season_id', $this->uri->segment(6))
->where('ilr_event_result.iracing_cust_id = ilr_champ.iracing_cust_id')
->where('ilr_event_result.schedule_id = ilr_champ.schedule_id')
->where('ilr_champ.schedule_id = ilr_events.schedule_id')
->where('ilr_events.track_id = ilr_tracks.track_id')
->select('
ilr_event_result.iracing_cust_id,
ilr_event_result.driver_title,
ilr_events.track_id,
ilr_tracks.turns,
ilr_season.drop_races,
ilr_season.multi_class,
ilr_season.car_name,
ilr_season.car2,
ilr_season.car3,
ilr_season.teams,
ilr_season.team_pts,
ilr_champ.team_id,
(select sum(ilr_champ.points - ilr_champ.pen_pts + ilr_champ.bonus_pts) from ilr_event_result where ilr_event_result.iracing_cust_id = ilr_champ.iracing_cust_id limit 1) as champ_points,
sum(ilr_champ.laps) as laps_total,
sum(ilr_champ.led) as led_total,
sum(ilr_champ.inc) as inc_total,
sum(ilr_champ.wins) as wins_total,
sum(ilr_champ.poles) as poles_total,
sum(ilr_champ.top5) as top5_total,
sum(ilr_champ.starts) as starts_total,
avg(ilr_champ.avg_s) as avg_s_total,
avg(ilr_champ.avg_f) as avg_f_total,
sum(ilr_champ.km * ilr_champ.laps) as km_total,
sum(ilr_champ.miles * ilr_champ.laps) as miles_total,
ilr_champ.team_name
')
->from('
ilr_event_result,
ilr_champ,
ilr_tracks
')
->join('ilr_season','ilr_season.season_id = ilr_champ.season_id')
->join('ilr_events', 'ilr_events.track_id = ilr_tracks.track_id')
->group_by('ilr_event_result.iracing_cust_id')
->order_by('champ_points desc, driver_title asc')
->get();
return $show_champ->result();
Then in my controller I added this to my Champ import. I know I got some db calls in my controller tisk tisk.

I can clean that up later.
Code:
$show_champ = $this->champ_model->get_champ_drop_import();
if($this->db->get('ilr_drop_races', array('season_id' => $this->uri->segment(6))))
{
$this->db->delete('ilr_drop_races', array('season_id' => $this->uri->segment(6)));
}
foreach($show_champ as $c)
{
$add = 0;
$drop = $this->champ_model->champ_drop_import($c->iracing_cust_id, $c->drop_races);
foreach($drop->result() as $d)
{
$add += $d->points + $d->bonus_pts - $d->pen_pts;
$import_drop = array(
'team_id' => $c->team_id,
'season_id' => $this->uri->segment(6),
'iracing_cust_id' => $c->iracing_cust_id,
'drop_total' => $c->champ_points - $add,
'team_name' => $c->team_name
);
}
$this->db->insert('ilr_drop_races', $import_drop);
}