2016-09-22 11 views
-1

enter image description here codeigniterとangularjsを使用してmysql dbからテーブルを表示しようとしています。このメッセージの修正方法重大度:通知 - >未定義のプロパティ:stdClass ::

<?php 
defined('BASEPATH') OR exit('No direct script access allowed'); 
?><!DOCTYPE html> 
<html ng-app="app"> 
<head> 
<meta charset="utf-8"> 
<title>List Show Data</title> 

<link rel="stylesheet" src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> 

</head> 
<body> 

<div ng-controller="decontroller"> 
<table class="table table-bordered table-striped table-hover"> 
<thead> 
<tr> 
<th>First Name</th> 
<th>Last Name</th> 
<th>Email</th> 
<th>Role</th> 
<th>Privileges</th> 
<th>User Name</th> 
</tr> 
</thead> 
<tbody> 
<tr ng-repeat="n in list_data"> 
    <td>{{n.First Name}}</td> 
    <td>{{n.Last Name}}</td> 
    <td>{{n.Email}}</td> 
    <td>{{n.Role}}</td> 
    <td>{{n.Privileges}}</td> 
    <td>{{n.User Name}}</td> 
</tr> 
</tbody> 
</table> 
</div> 
<script type="text/javascript" href="/public/js/angular.js"> </script> 
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js"> </script> 
<script type="text/javascript"> 
var app = angular.module('app',[]); 
app.controller('decontroller', function($scope,$http){ 
    $scope.list_data=[]; 
    $http.get("ajax_load_data").success(function(result){ 
     $scope.list_data=result; 
    }); 
}); 
</script> 
</body> 
</html> 

この私のコントローラlist_show_data.php: これが私の見解である

Severity: Notice --> Undefined property: stdClass::$First C:\xampp\htdocs\stlc\application\controllers\MainTest.php 38 
ERROR - 2016-09-22 16:31:19 --> Severity: Notice --> Undefined property: stdClass::$Last C:\xampp\htdocs\stlc\application\controllers\MainTest.php 39 
ERROR - 2016-09-22 16:31:19 --> Severity: Notice --> Undefined property: stdClass::$User C:\xampp\htdocs\stlc\application\controllers\MainTest.php 43 
+0

stlc_usersテーブルを確認すると、おそらく列が間違っている可能性があります。 'var_dump($ r)'は – aynber

+0

も明らかにこれを助けます: '$ data_arr [$ i] ['名]' = $ r->最初です。 '$ r'にあるものをチェックするような、基本的なデバッグを行いましたか? –

+0

@MarcB、 '$ r'は' foreach($ res as $ r) 'によって提供されている現在の値です – DFriend

答えて

2
:MainTest.php

<?php 
defined('BASEPATH') OR exit('No direct script access allowed'); 

class MainTest extends CI_Controller { 

/** 
* Index Page for this controller. 
* 
* Maps to the following URL 
*  http://example.com/index.php/welcome 
* - or - 
*  http://example.com/index.php/welcome/index 
* - or - 
* Since this controller is set as the default controller in 
* config/routes.php, it's displayed at http://example.com/ 
* 
* So any other public methods not prefixed with an underscore will 
* map to /index.php/welcome/<method_name> 
* @see https://codeigniter.com/user_guide/general/urls.html 
*/ 
public function list_show_data() 
{ 

    $this->load->helper('url'); 
    $this->load->view('list_show_data'); 

} 

public function ajax_load_data() 
{ 
    $this->load->helper('url'); 
    $res = $this->db->get('stlc_users')->result(); 
    $data_arr = array(); 
    $i=0; 
    foreach($res as $r) 
    { 
     $data_arr[$i]['First Name'] = $r->First ; 
     $data_arr[$i]['Last Name'] = $r->Last ; 
     $data_arr[$i]['Email'] = $r->Email; 
     $data_arr[$i]['Role'] = $r->Role; 
     $data_arr[$i]['Privileges'] = $r->Privileges; 
     $data_arr[$i]['User Name'] = $r->User ; 
     $i++; 
    } 
    echo json_encode($data_arr); 
} 

}

は、これは私が取得していますエラーです

このエラーメッセージは、$rオブジェクトが、 DBテーブルstlc_usersには、LastUserの2つのプロパティがありません。たいていの理由は、DBテーブルにこれらの名前の列がないことです。

+0

画像リンクを追加しました。設定されているようです。私はあなたが明らかに言うことができるように初心者です。 – excelsiorone

+1

カラム名は「First_Name」、「Last_Name」、および「User_Name」です。私は100%確信していませんが、おそらく '_ 'の近くにスペース文字も含まれています。その場合は、列名の名前を変更し、空白文字を除外してください。次に、あなたのコードで '$ r-> First_Name'、' $ r-> Last_Name'、そして '$ r-> User_Name'を使うことができます。 –

+0

ありがとうございます!私はそれが働いた!あなたは揺れる – excelsiorone

関連する問題