php - 收到错误未定义的属性:stdClass::$workingtime

标签 php mysql codeigniter

我正在尝试从数据库获取输出,但收到错误,例如遇到 PHP 错误 严重性:通知

消息:未定义的属性:stdClass::$workingtime 下面是我的代码。带有 Controller 、模型和 View 。在 $workingtime 附近的 View 上出现错误

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);
}

型号:

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'");
}

查看:

<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>

我正在尝试从数据库获取输出,但收到类似“PHP 错误”的错误 我正在尝试从数据库获取输出,但收到类似“遇到 PHP 错误”的错误 我正在尝试从数据库获取输出,但收到类似“PHP 错误”的错误遇到了。

消息:未定义的属性:stdClass::$workingtime。 在 $workingtime 附近查看时出现错误

最佳答案

我认为您可能无法在模型响应中获取 workingtime 字段。重新检查您的 SQL 查询。

关于php - 收到错误未定义的属性:stdClass::$workingtime,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49248956/

相关文章:

mysql - 我可以从 .sql 创建初始 CodeIgniter 数据库迁移吗?

php - JQuery - 组复选框

mysql - 从 MYSQL 将数据填充到 elasticsearch 的良好实践

mysql - 2017 年最佳免费 MySQL 分析器

MySQL - 根据其他表更新用户数据

php - 如何从 codeigniter 中的 varchar 字段获取整数值的 max() ?

php - 在 codeIgniter 中连接表后无法显示完整数据

php - 将 lat/lng 与另一个 lat/lng 进行比较

php - 在 Windows 命令行上运行 PHP 脚本时,PDO ODBC 连接出现 "Could not find driver"错误

php - cake php 检查自定义列中是否存在记录