show ARRAY Codeigniter

0

I have the following code where I do a search with a worker code, but now I want to do it with more workers. It shows me only the last selected worker.

Controller.

       // $persona =  $this->input->post('persona');
$this->form_validation->set_rules('persona[]', 'persona','required|trim',array(
        'required' => 'Seleccione una maquina'
    ));

        foreach ($this->input->post('persona') as $persona) {
        $desde =$this->input->post('fechadesde');
        $hasta =$this->input->post('fechahasta');

        $data['desde'] = $desde;
        $data['hasta'] = $hasta;

            $data['tipo'] = $this->input->post('customRadio');
            $data['nombre'] =$this->m->verificarCodigo($persona);
            $data['actividades']= $this->report->getActividades($desde,$hasta,$persona);
        }

     // print_r($data);

        $this->load->view('report/person-result',$data);

My sight.

   <?php if ($nombre): ?>
    <?php echo $nombre->Nombre; ?>
    <?php endif;?> </h4>

<?php $fechas = array(); ?>

<?php if ($seguimientos): ?>
<?php


    foreach ($seguimientos as $seguimiento) {
        $fechas[$seguimiento->fechaSeguimiento][] = $seguimiento;

    }
?>
      <?php  foreach ($fechas as $fecha):?>

<table class="table table-hover dataTable no-footer">
    <thead>
        <tr>
            <th>Fecha</th>

        </tr>
    </thead>

    <?php foreach ($fecha as $seguimiento): ?>
    <tr>
        <td></td>
    </tr>

    <?php endforeach; ?>
</table>

<?php endforeach; ?>

<?php endif; ?>

Should I modify the variable $ data? And add a foreach in the view?

    
asked by MoteCL 06.08.2018 в 17:18
source

1 answer

0

The logic is wrong in the controller (I think).

The current operation of your code is as follows:

Itera about $ this-> input-> post ('person') waiting for it to be an array and perform the operations within the for cycle, but only the first will persist in the view, a way to fix this would be to the following way:

$personas = $this->input->post('persona');
$desde =$this->input->post('fechadesde');
$hasta =$this->input->post('fechahasta');

//Este array contendrá la salida hacia la vista.
$data = array();
//Compruebo que realmente sea un array.
is_array($personas)
{
    //Declaro un array auxiliar.
    $aux = array();
    foreach ($personas as $persona) 
    {
        $aux['desde'] = $desde;
        $aux['hasta'] = $hasta;
        $aux['tipo'] = $this->input->post('customRadio');
        $aux['nombre'] =$this->m->verificarCodigo($persona);
        $aux['actividades']= $this->report->getActividades($desde,$hasta,$persona);
        //Agrego el elemento individual al array que contendra todos.
        array_push($data, $aux);
    }
    $this->load->view('report/person-result',$data);
}
else
{
    $aux['desde'] = $desde;
    $aux['hasta'] = $hasta;
    $aux['tipo'] = $this->input->post('customRadio');
    $aux['nombre'] =$this->m->verificarCodigo($persona);
    $aux['actividades']= $this->report->getActividades($desde,$hasta,$persona);
    $this->load->view('report/person-result',$aux);
}

I hope you have managed to convey my idea. Then you must treat the $ data or $ aux from the view.

    
answered by 07.08.2018 в 00:57