简体   繁体   中英

getting error Undefined property: stdClass::$workingtime

I am trying get output from database but am getting error like A PHP Error was encountered Severity: Notice

Message: Undefined property: stdClass::$workingtime below is my code.with controller,model and view.getting error on view near $workingtime

controller:

public function employee($id)
{

    $user_record = $this->db->query("select * from usr_data where usr_id=$id")->result();
    $data['title'] = 'User Dashboard';
    $data['user_record'] = null;
    $data['active_courses'] = [];
    $data['active_coursess'] = [];
    $data['course_status'] = [];
    if(count($user_record)) {
        $user_record = $user_record[0];
        $data['title'] = ucwords($user_record->firstname.' '.$user_record->lastname).' Dashboard';
        $data['user_record'] = $user_record;

        $active_courses = $this->base_model->getCourseData($id);
        $active_coursess =$this->base_model->gettestDetails($id);
        $data['active_courses'] = $active_courses;
        if(count($active_courses)) {
            $data['course_status'] = $this->base_model->getCourseStatus($active_courses[0]->obj_id, $id);

            $data['time_details'] = $this->base_model->getActiveCourseTimeSpent($active_courses[0]->obj_id, $id);
        }
    }
    $this->load->view('employe-dashboard', $data);
}

Model:

public function gettestDetails($user_id)
{
    return $this->executeSelectQuery("SELECT o.title ,ta.*,tpr.workingtime,tcr.mark_official,(tcr.reached_points/tcr.max_points)*100 as result FROM object_data o,usr_data u,tst_active ta, tst_tests tt,tst_pass_result tpr, tst_result_cache tcr WHERE u.usr_id=ta.user_fi and tt.obj_fi=o.obj_id and ta.test_fi=tt.test_id AND ta.active_id=tpr.active_fi AND tcr.active_fi=ta.active_id AND u.usr_id=$user_id and o.type='tst'");
}

View:

<table class="table" id="myTable">
    <thead>
        <tr>

            <th>Course Name</th>
            <th>Duration</th>
            <th>Attempts</th>
            <th>Status</th>
            <th>Result</th>
        </tr>
    </thead>

    <tbody>

    <?php
        foreach($active_courses as $test) { 
            $inner_details = $this->base_model->gettestDetails($user_record->usr_id);
            //echo "<pre>"; print_r($inner_details); die();
            //   $time_spent = 0;
            // if($inner_details)
            //   $time_spent = $inner_details->workingtime;

    ?>
    <tr>
        <td><?php echo ucfirst($test->title); ?></td>
            <td>
                <?php echo $test->workingtime; ?> 

            </td>
            <td> 
                <?PHP echo $test->tries ?>
            </td>
            <td></td>

        </tr>
        <?php } ?>
    </tbody>
</table>

I am trying get output from database but am getting error like A PHP Error was encountered am trying get output from database but am getting error like A PHP Error was encountered am trying get output from database but am getting error like A PHP Error was encountered.

Message: Undefined property: stdClass::$workingtime. getting error on view near $workingtime

I think you may not getting workingtime field in model response. Re-Check your SQL query.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM