【问题标题】:getting error Undefined property: stdClass::$workingtime得到错误未定义的属性:stdClass::$workingtime
【发布时间】:2018-08-21 06:48:03
【问题描述】:

我正在尝试从数据库中获取输出,但遇到了诸如 A PHP Error 之类的错误 严重性:通知

消息:未定义的属性:下面的 stdClass::$workingtime 是我的代码。带有控制器、模型和视图。$workingtime 附近的视图出现错误

控制器:

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 附近的视图出现错误

【问题讨论】:

  • 试试这个
  • 如果我像您的代码一样编写,则会收到此错误遇到 PHP 错误严重性:错误消息:无法使用 stdClass 类型的对象作为数组
  • 您能否在视图中打印 $test 的输出?
  • 只需 var_dump $test 并将其添加到问题中。
  • object(stdClass)[20] public 'obj_id' => string '3121' (length=4) public 'type' => string 'crs' (length=3) public 'title' = > string 'Test by aditya' (length=14) public 'create_date' => string '2017-10-19 11:49:41' (length=19) public 'last_update' => string '2017-10-19 11 :49:52' (length=19) public 'import_id' => null public 'usr_id' => string '3213' (length=4) public 'origin_ts' => string '0' (length=1) 和错误遇到 PHP 错误严重性:错误消息:不能使用 stdClass 类型的对象作为数组

标签: php mysql codeigniter


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-10-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-29
    • 1970-01-01
    相关资源
    最近更新 更多