I would like to know how to list data in different bootstrap tables using Codeigniter

Asked

Viewed 25 times

0

This is the view named Dashboard.php

<main role="main" class="col-md-10 ml-sm-auto col-lg-10 px-4">
<div style="top:-5px" class="col-md-12 d-flex justify-content-between flex-wrap align-items-center pt-3 pb-2 mb-3 border-bottom">
    <h1 class="h2">Dashboard</h1>
</div>
<div class="row">
    <div class="col-md-6">
        <table class="table table-bordered">
            <thead class="thead-light">
                <tr style="text-align:center; font-size:12pt">
                    <th style="background:#585858; color:white" colspan="2">Regs para Remover Hoje:</th>
                    <th style="background:#585858; color:white"><?php $matricula = date ("d-m-Y");echo"<input style='background:#585858; color:white; border:none; text-align:center' type='text' value='$matricula'";?> </th>
                        <tr style="text-align:center; font-size:12pt">
                            <th style="padding:5px">ID</th>
                            <th style="padding:5px;">Nome</th>
                            <th style="padding:5px">ID Unico do TS</th>
                        </tr>
                </tr>
            </thead>
            <?php foreach($cadastros as $cad){?>
                <tr style="text-align:center; font-size:12pt">
                    <td style="padding:5px"><?= $cad->id; ?></td>
                    <td style="padding:5px; text-align:left"><?= $cad->nick; ?></td>
                    <td style="padding:5px"><?= $cad->id_unico; ?></td>
                </tr>
            <?php }?>
        </table>
    </div>
    <div class="col-md-6">
        <table class="table table-bordered">
            <thead class="thead-light">
                <tr style="text-align:center; font-size:12pt">
                    <th style="background:#585858; color:white" colspan="3">Registros não Removidos</th>
                        <tr style="text-align:center; font-size:12pt">
                            <th style="padding:5px">ID</th>
                            <th style="padding:5px;">Nome</th>
                            <th style="padding:5px">ID Unico do TS</th>
                        </tr>
                </tr>
            </thead>
            <?php foreach($cadastros as $cad){?>
                <tr style="text-align:center; font-size:12pt">
                    <td style="padding:5px"><?= $cad->id; ?></td>
                    <td style="padding:5px; text-align:left"><?= $cad->nick; ?></td>
                    <td style="padding:5px"><?= $cad->id_unico; ?></td>
                </tr>
            <?php }?>
        </table>
    </div>
</div>

And this is the controller named after statistics.php

public function index($indice=null)
{
    $this->verificar_sessao();
    $this->db->select('*');
    $this->db->where('data_vencimento =', date('Y-m-d'));
    $dados['cadastros'] = $this->db->get('cadastro')->result();
    $this->load->view('includes/html_header');
    $this->load->view('includes/menu');

    $this->load->view('dashboard',$dados);
    $this->load->view('includes/html_footer');
}

Aee gets like this https://i.imgur.com/Spkpiy7.png

I wonder if there is as the first table I list the records equal to the date there above 07/04/2019, as this and in the second table list only records prior to that date 07/04/2019.

1 answer

0

This way you’ve crafted it, it won’t work. There’s also an error regarding your controller. If you are working with MVC, I believe that you should insert the registry return Function within the model. In my view, it would look like this:

Controller - stats.php

public function index($indice=null)
{
    $this->verificar_sessao();
    $this->load->model('estatisticas_model');

    $dados['cadastros_atual'] = $this->estatisticas_model->get_estatisticas('atual'); // data atual
    $dados['cadastros_anterior'] = $this->estatisticas_model->get_estatisticas('anterior'); // data anterior

    $this->load->view('includes/html_header');
    $this->load->view('includes/menu');

    $this->load->view('dashboard',$dados);
    $this->load->view('includes/html_footer');
}

Model - statistics

public function get_estatisticas($tipo=null){
    if($tipo){
        switch($tipo){
            case 'atual':
                $this->db->select('*');
                $this->db->where('data_vencimento =', date('Y-m-d'));
                $result = $this->db->get('cadastro')->result();         
            break; 

            case 'anterior':
                $this->db->select('*');
                $this->db->where('data_vencimento <=', date('Y-m-d'));
                $result = $this->db->get('cadastro')->result();         
            break;          
        }

        return $result;
    } else {
        return "Nenhum tipo registrado.";
    }
}

View - stats.php

<main role="main" class="col-md-10 ml-sm-auto col-lg-10 px-4">
<div style="top:-5px" class="col-md-12 d-flex justify-content-between flex-wrap align-items-center pt-3 pb-2 mb-3 border-bottom">
    <h1 class="h2">Dashboard</h1>
</div>
<div class="row">
    <div class="col-md-6">
        <table class="table table-bordered">
            <thead class="thead-light">
                <tr style="text-align:center; font-size:12pt">
                    <th style="background:#585858; color:white" colspan="2">Regs para Remover Hoje (atual)</th>
                    <th style="background:#585858; color:white"><?php $matricula = date ("d-m-Y");echo"<input style='background:#585858; color:white; border:none; text-align:center' type='text' value='$matricula'";?> </th>
                        <tr style="text-align:center; font-size:12pt">
                            <th style="padding:5px">ID</th>
                            <th style="padding:5px;">Nome</th>
                            <th style="padding:5px">ID Unico do TS</th>
                        </tr>
                </tr>
            </thead>
            <?php foreach($cadastros_atual as $cad){?>
                <tr style="text-align:center; font-size:12pt">
                    <td style="padding:5px"><?= $cad->id; ?></td>
                    <td style="padding:5px; text-align:left"><?= $cad->nick; ?></td>
                    <td style="padding:5px"><?= $cad->id_unico; ?></td>
                </tr>
            <?php }?>
        </table>
    </div>
    <div class="col-md-6">
        <table class="table table-bordered">
            <thead class="thead-light">
                <tr style="text-align:center; font-size:12pt">
                    <th style="background:#585858; color:white" colspan="3">Registros não Removidos (anterior)</th>
                        <tr style="text-align:center; font-size:12pt">
                            <th style="padding:5px">ID</th>
                            <th style="padding:5px;">Nome</th>
                            <th style="padding:5px">ID Unico do TS</th>
                        </tr>
                </tr>
            </thead>
            <?php foreach($cadastros_anterior as $cad){?>
                <tr style="text-align:center; font-size:12pt">
                    <td style="padding:5px"><?= $cad->id; ?></td>
                    <td style="padding:5px; text-align:left"><?= $cad->nick; ?></td>
                    <td style="padding:5px"><?= $cad->id_unico; ?></td>
                </tr>
            <?php }?>
        </table>
    </div>
</div>
  • I’m new in Codeigniter bro, for now I’m only using the Views and Controllers, I didn’t get to use the Models, but I’ll see how it works and implement your code here. thanks since you.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.