1
Good morning, I’m trying to carry out a very simple project using the Codeigniter framework, but I always had this question before even implementing a framework, I always beat myself up to receive data that is an array, and show these results on the screen to the user, I usually perform a query in the database and want to show these results to the user, I have not been able to use with foreach because it always shows me only the last result, and I want all the records that the query to the database returned me. Can anyone help me? or link to an article on the subject?
I have an example that I show users the schedules that are in the database and it selects some of these schedules, but before registering the schedules that he selected I want, impose on the screen with echo to confirm the request of the user.
MODEL
public function select_horarios(){
$this->db->select('hora');
$this->db->from('horarios');
$query = $this->db->get();
if($query){
return $query->result_array();
}else{
return false;
}
}
CONTROLLER
public function index(){
$this->load->model('administrativo/abrirfechar_agenda', 'agenda');
if(isset($_POST['acao']) && $_POST['acao'] == 'Abrir Agenda >>'){
$data = $this->input->post('data');
$horarios = $this->input->post('horarios');
//Data Formatada
$data_form = date('d/m/Y', strtotime($data));
if(empty($data)){
echo 'Selecione a Data';
}else if(empty($horarios)){
echo 'Informe os horarios para a data '.$data_form;
}else{
//INICIANDO A CONSULTA PELA DATA E HORARIOS SELECIONADOS
//Tratamento de matriz
foreach($horarios as $linha){
$horas = $linha;
}
//INICIANDO O CADASTRO NO BD PARA ABERTURA DE AGENDA.
echo "Passou na validação ".$horas;
}
}
$dados['horarios'] = $this->agenda->select_horarios();
$this->load->view('administrativo/abrirfechar_agenda', $dados);
}
VIEW
echo form_label('Selecione os Horários: ', 'horario');
echo "</br>";
foreach($horarios as $linha){
echo form_checkbox('horarios[]',$linha['hora']);
echo $linha['hora'];
echo "</br>";
}
Please post the code you are trying to implement, from model, view and controller.
– Sr. André Baill