PHP Message Error: Can not use object of type CI_DB_mysqli_result as array

0

I'm doing array and I get the following error:

  

Fatal error: Can not use object of type CI_DB_mysqli_result as array in   C: \ xampp \ htdocs \ olPrueba2 \ application \ controllers \ Admin.php on line   748 A PHP Error was encountered Severity: Error

     

Message: Can not use object of type CI_DB_mysqli_result as array

     

Filename: controllers / Admin.php

     

Line Number: 748

     

Backtrace:

The array will have data that I get from the database, this is the method where I generate it:

public function teniurtype()
{

            $postData = $this->input->post();
            //$postName = json_decode(stripslashes($postData['roster_salesforcename']));
            $postAdvocate = $postData['sup'];
            $Date = date("Y-m-d H:i:s");
            $arrayMtd = array();
            $arrayAdvocates = array();
            $arrayhire_date = array();
            $arrayhire_date = $this->ol_model->gethire_date($postAdvocate);
            $arrayAdvocates = $this->ol_model->getadvocatesSup($postAdvocate);
            $sizeArrAdv = sizeof($arrayAdvocates);
            $bandera = false;
            $dateC = new DateTime($Date);
            $monthC = $dateC->format('m');
            $yearC =  $dateC->format('Y');
            $dayC = $dateC->format('d');
            $Type3 = "T3";
            $Type2 = "T2";
            $Type1 = "T1";
            $monthCn = (int)$monthC;
            $yearCn  = (int)$yearC ;
            $i=0;
            for ($i=0; $i < $sizeArrAdv ; $i++) {
                $Yhire_date = $this->ol_model->getyearHire($arrayAdvocates[$i]["roster_salesforcename"]);
                $Mhire_date = $this->ol_model->getmonthHire($arrayAdvocates[$i]["roster_salesforcename"]);
                $Yhire_daten = (int)$Yhire_date;
                $Mhire_daten = (int)$Mhire_date;
                $u=($yearCn-$Yhire_daten)*12;
                $d=$u+($monthCn-1);
                $t=$d-($Mhire_daten);
                $monthworked =$t;
                //$monthworked = ((($yearC)-($Yhire_date))*12)+($monthC-1)-($Mhire_date);

                if ($monthworked > 11){
                    if($monthworked >= 12 && $monthworked < 18 ){
                        if ($Mhire_date%2==0){
                            $mworked = array('advocate' => $arrayAdvocates[$i]["roster_salesforcename"], 'Hire_Date' => $arrayhire_date[$i]["roster_hire_date"], 'Tenure' => $monthworked, 'Type' => $Type3, 'Bono' => "70.000");
                        }else{
                            $mworked = array('advocate' => $arrayAdvocates[$i]["roster_salesforcename"], 'Hire_Date' => $arrayhire_date[$i]["roster_hire_date"], 'Tenure' => $monthworked, 'Type' => $Type3, 'Bono' => "80.000");

                        }
                    }elseif ($monthworked >= 18 && $monthworked < 24) {
                            if ($Mhire_date%2==0){
                                $mworked = array('advocate' => $arrayAdvocates[$i]["roster_salesforcename"], 'Hire_Date' => $arrayhire_date[$i]["roster_hire_date"], 'Tenure' => $monthworked, 'Type' => $Type3, 'Bono' => "150.000");
                            }else{
                                $mworked = array('advocate' => $arrayAdvocates[$i]["roster_salesforcename"], 'Hire_Date' => $arrayhire_date[$i]["roster_hire_date"], 'Tenure' => $monthworked, 'Type' => $Type3, 'Bono' => "150.000");


                            }
                    }elseif ($monthworked > 24) {
                            if ($Mhire_date%2==0){
                                $mworked = array('advocate' => $arrayAdvocates[$i]["roster_salesforcename"], 'Hire_Date' => $arrayhire_date[$i]["roster_hire_date"],'Tenure' => $monthworked, 'Type' => $Type3, 'Bono' => "220.000");
                            }else{
                                $mworked = array('advocate' => $arrayAdvocates[$i]["roster_salesforcename"], 'Hire_Date' => $arrayhire_date[$i]["roster_hire_date"], 'Tenure' => $monthworked, 'Type' => $Type3, 'Bono' => "230.000");
                            }
                    }
                }else{
                    echo 'No cumple el requisito de cantidad de meses trabajados';
                }
                array_push($arrayMtd, $mworked);
        }
        echo json_encode($arrayMtd);
}
    
asked by user80520 07.04.2018 в 01:14
source

2 answers

0

The error seems to be in the model where you make the query, it is returning an Object instead of an Array. look for something similar to this:

$result = $this->db->query($sql);
return $result->result_array();

If it were: return $result; the error jumps later when wanting to use it as an array

    
answered by 07.04.2018 / 02:27
source
0

Your problem is here:

$arrayhire_date = $this->ol_model->gethire_date($postAdvocate);
$arrayAdvocates = $this->ol_model->getadvocatesSup($postAdvocate);

Change these lines by:

$arrayhire_date = $this->ol_model->gethire_date($postAdvocate)->result_array();
$arrayAdvocates = $this->ol_model->getadvocatesSup($postAdvocate)->result_array();

In line 748 you refer to these varibles as arrays, but they are objects. That's what result_array () is for. Alternatively, you can refer to the variables with - > instead the brackets.

    
answered by 09.04.2018 в 17:51