Welcome Guest, Not a member yet? Register   Sign In
sub query problems SOLVED
#12

[eluser]srpurdy[/eluser]
Finally managed to figure this out. Breaking this post into multiple posts. Too much code.

Thanks for your help Caio Smile

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


Messages In This Thread
sub query problems SOLVED - by El Forum - 04-27-2010, 10:48 PM
sub query problems SOLVED - by El Forum - 04-28-2010, 02:49 AM
sub query problems SOLVED - by El Forum - 04-28-2010, 08:48 AM
sub query problems SOLVED - by El Forum - 04-28-2010, 03:18 PM
sub query problems SOLVED - by El Forum - 05-01-2010, 06:00 PM
sub query problems SOLVED - by El Forum - 05-02-2010, 06:10 PM
sub query problems SOLVED - by El Forum - 05-04-2010, 09:28 AM
sub query problems SOLVED - by El Forum - 05-08-2010, 01:45 PM
sub query problems SOLVED - by El Forum - 05-10-2010, 11:28 AM
sub query problems SOLVED - by El Forum - 05-10-2010, 11:37 AM
sub query problems SOLVED - by El Forum - 05-10-2010, 11:57 AM
sub query problems SOLVED - by El Forum - 06-07-2010, 06:06 AM
sub query problems SOLVED - by El Forum - 06-07-2010, 06:11 AM
sub query problems SOLVED - by El Forum - 06-07-2010, 06:11 AM
sub query problems SOLVED - by El Forum - 06-07-2010, 07:15 AM



Theme © iAndrew 2016 - Forum software by © MyBB