ERROR: Type: ArgumentCountError, Too few arguments to function

0

It happens that I am showing some data from my Database through some Foreach, in which I am using echo to show the value of each field that I require. So far I have used in my query sql, in the WHERE condition any value that throws a result to show it, however this must do it by means of some variable, in this case it would be $ rut_usu, which will store the selected rout from a select (listboxt) in the view. But when adding in the model, in the sql query my variable (which does not yet have any value, because I have not selected any value from the listboxt) throws me the following error:

An uncaught Exception was encountered

Type: ArgumentCountError

Message: Too few arguments to function M_Calendar::monday(), 0 passed in C:\xampp\htdocs\SAE\application\controllers\C_Calendar.php on line 23 and exactly 1 expected

Filename: C:\xampp\htdocs\SAE\application\models\M_Calendar.php

Line Number: 106

Backtrace:

File: C:\xampp\htdocs\SAE\application\controllers\C_Calendar.php
Line: 23
Function: monday

File: C:\xampp\htdocs\SAE\index.php
Line: 315
Function: require_once

What would be the solution to this, should I do what I require in some other way?

I leave my code:

Controller:

public function index(){


        $this->load->view('layouts/Header.php');
        $this->load->view('layouts/Menu.php');
        $this->load->model('M_Calendar');
        $data['monday'] = $this->M_Calendar->monday();
        $data['tuesday'] = $this->M_Calendar->tuesday(); 
        $data['Wednesday'] = $this->M_Calendar->wednesday();
        $data['thursday'] = $this->M_Calendar->thursday();
        $data['friday'] = $this->M_Calendar->friday();  
        $data['saturday'] = $this->M_Calendar->saturday();
        $data['usuarios'] = $this->M_Calendar->get_usuarios();

        $this->load->view('usuarios/V_Consulta_Horarios.php',$data);
        $this->load->view('layouts/Footer.php');




}

Model (I have several functions like this, from Monday to Saturday)

public function  monday($rut_usu){


$this->db->select('MIN(horario.hrs_ini) AS hrs_ini, MAX(horario.hrs_ter) AS hrs_ter ');
$this->db->from('horario');
$this->db->join('usuarios','horario.rut_usu = usuarios.rut_usu');
$this->db->where('usuarios.rut_usu',$rut_usu); 
$this->db->where('horario.lunes','ATTE. ESTUDIANTES');
$this->db->where('fecha_registro = (SELECT MAX(fecha_registro) FROM horario)');
$this->db->limit('14');
$monday = $this->db->get();


  if($monday->num_rows() > 0 ){

    return $monday->result();

    }

}

I'm showing the variables inside a javascript using fullcalendar, which as I mentioned before worked fine

businessHours: [ // specify an array instea
{
    dow: [ 1], // Monday

    <?php foreach($monday as $row){?>
       start: '<?php  $inicio= "00:00"; $start1_ok = $row->hrs_ini;

    if (empty($start1_ok)) { echo $inicio;}

    else { echo $start1_ok;} ?>',  // empty evalúa si el campo se encuentra vació o si es cero
    end: '<?php echo $row->hrs_ter ;?>' 
    <?php }?>

},
    
asked by CristianOx21 10.10.2017 в 23:00
source

1 answer

1

The error you are receiving is because you are not sending all the required parameters in the where.

Your last where is this:

$this->db->where('fecha_registro = (SELECT MAX(fecha_registro) FROM horario)');

So you are missing the second necessary parameter in the where.

The first parameter is the column you are going to compare, and the second is the value that you compare.

TU where it should look like:

$this->db->where('fecha_registro', '(SELECT MAX(fecha_registro) FROM horario)');

In addition to this, the monday function needs a parameter

public function  monday($rut_usu)

To prove that you are obtaining data in your query, send a parameter $ rut_usu that is in your database, something like this:

$data['monday'] = $this->M_Calendar->monday("1234567");
    
answered by 10.10.2017 в 23:12