Welcome Guest, Not a member yet? Register   Sign In
Problem: Join repeats records?
#1

Controller file:
public function operadora($elev_opename_id)
{
// loads the class file
    $this->load->model('tabelas/Elevsaude_model');
    // Run the loaded class method
    $dataone['plansopers'] = $this->Elevsaude_model->plansoper_head($elev_opename_id);

// loads the class file
    $this->load->model('tabelas/Elevsaude_model');
    // Run the loaded class method
    $datatwo['planstypes'] = $this->Elevsaude_model->planstypes_head($elev_opename_id);

//Show data view
$this->load->view('tabelas/html_header');
$this->load->view('tabelas/plansoper_head', $dataone);
$this->load->view('tabelas/planstype_head', $datatwo);
$this->load->view('tabelas/html_footer');
}


Model file:
// method that lists types of plans from operators:
public function planstypes_head($elev_opename_id) {
    $this->db->select('*');
    $this->db->from('elev_plans_types');
    $this->db->join('elev_share_plans', 'elev_share_plans.elev_opename_id = elev_plans_types.elev_opename_id');
    $this->db->where('elev_plans_types.elev_opename_id', $elev_opename_id);
    $query = $this->db->get();
    return $query->result();
}

View file:
        <?php
            foreach ($planstypes as $view) {
                echo '
                <div class="planstype-content-strucs">
                    <div class="planstype-header-strucs">
                        <div class="planstype-name-strucs"><h1 class="planstype-hone-strucs">' . $view->elev_platys_name . '</h1></div>
                        <button class="planstype-button-strucs"><img src="../../../assets/fgs/'. $view->elev_platys_help .'"  class="operator-brand-zoom-strucs"></button>
                    </div>
                    <div class="planshare-content-strucs" style=" ' . $view->elev_sarplans_divmain . ' ">
                        <div class="planshare-left-strucs" style=" ' . $view->elev_sarplans_divleft . ' "><h1 class="planshare-hone-strucs">' . $view->elev_sarplans_titleleft . '</h1></div>
                        <div class="planshare-right-strucs" style=" ' . $view->elev_sarplans_divright . ' "><h1 class="planshare-hone-strucs">' . $view->elev_sarplans_titleright . '</h1></div>
                    </div>
                </div>
                ';
            };
        ?>

Link for site:  http://elevsaude.webstrucs.com/tabelas/e...peradora/1

???

Reply
#2

You only need to load the model once this is usually done in the controller constructor.

Your loading it multiple times in your controller, queries are saved but you can turn them off.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

(06-25-2016, 02:27 AM)InsiteFX Wrote: You only need to load the model once this is usually done in the controller constructor.

Your loading it multiple times in your controller, queries are saved but you can turn them off.

Ok.

See as it was...

Controller file:
public function __construct() {
parent::__construct();
// loads the class file
   $this->load->model('tabelas/Elevsaude_model');
}

public function operadora($elev_opename_id)
{
    // Run the loaded class method
    $dataone['plansopers'] = $this->Elevsaude_model->plansoper_head($elev_opename_id);
    // Run the loaded class method
    $datatwo['planstypes'] = $this->Elevsaude_model->planstypes_head($elev_opename_id);

//Show data view
$this->load->view('tabelas/html_header');
$this->load->view('tabelas/plansoper_head', $dataone);
$this->load->view('tabelas/planstype_head', $datatwo);
$this->load->view('tabelas/html_footer');
}

Model file:
// method that lists types of plans from operators:
public function planstypes_head($elev_opename_id) {
    $this->db->select('*');
    $this->db->from('elev_plans_types');
    $this->db->join('elev_share_plans', 'elev_share_plans.elev_opename_id = elev_plans_types.elev_opename_id');
    $this->db->where('elev_plans_types.elev_opename_id', $elev_opename_id);
    $query = $this->db->get();
    return $query->result();
}

View file:
        <?php
            foreach ($planstypes as $view) {
                echo '
                <div class="planstype-content-strucs">
                    <div class="planstype-header-strucs">
                        <div class="planstype-name-strucs"><h1 class="planstype-hone-strucs">' . $view->elev_platys_name . '</h1></div>
                        <button class="planstype-button-strucs"><img src="../../../assets/fgs/'. $view->elev_platys_help .'"  class="operator-brand-zoom-strucs"></button>
                    </div>
                    <div class="planshare-content-strucs" style=" ' . $view->elev_sarplans_divmain . ' ">
                        <div class="planshare-left-strucs" style=" ' . $view->elev_sarplans_divleft . ' "><h1 class="planshare-hone-strucs">' . $view->elev_sarplans_titleleft . '</h1></div>
                        <div class="planshare-right-strucs" style=" ' . $view->elev_sarplans_divright . ' "><h1 class="planshare-hone-strucs">' . $view->elev_sarplans_titleright . '</h1></div>
                    </div>
                </div>
                ';
            };
        ?>

Link for site:  http://elevsaude.webstrucs.com/tabelas/e...peradora/1
Obs: Continued tripling?

Reply
#4

Your sql must be grabbing more then one database record.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#5

(06-26-2016, 02:36 PM)InsiteFX Wrote: Your sql must be grabbing more then one database record.

The (t.a) has four lines that relate to the other four lines (t.b) The query is realized by means of a (user.id) that exists in both tables.

Reply




Theme © iAndrew 2016 - Forum software by © MyBB