无法访问Controller中的$ data值

时间:2016-08-05 04:09:03

标签: php mysql codeigniter-2

$this->db->select("*");
$this->db->from("panTab");         
$this->db->where("QCJobPanelTestId = ",$TestId);
$query = $this->db->get();
$data['get_JobPan_Data'] = $query->result();

for($i = 0; $i < sizeof($data['get_JobPan_Data']);$i++)
{
$table = "Form1";
$whereField1 = "QC1TestId";
$whereField2 = "QC1JobPanelId";
$currDiv = "form1";
$this->db->select("*");
$this->db->from($table);
$this->db->where($whereField1." = ",$TestId); 
$this->db->where($whereField2." = ",$data['get_JobPan_Data'][$i]['QCJobPanelId']); //--This value gives an error . How to access it?
$query1 = $this->db->get();
$data['getTestData'] = $query1->result();
}

即将推出的数据

 Array ( 
        [get_JobPan_Data] => Array ( 
            [0] => stdClass Object( 
                [QCJobPanelId] => 293 [QCJobPanelNo] => 1 
                [QCJobPanelDesc] => Pan 1 
                [QCJobPanelJobId] => 3 
                [QCJobPanelPanelId] => 0 
                [QCJobPanelTestId] => 63 
            ) 
            [getTestData] => Array ( 
                [0] => stdClass Object ( 
                    [QC1Id] => 77 
                    [QC1JobId] => 3 
                    [QC1TestId] => 63 
                    [QCTestDesc] => 0 
                    [QC1DielectricACC_LC] => 0 
                    [QC1DielectricACC_IRA] => 0 
                    [QCRemark] => Completed 
                    [QCTestedBy] => aa 
                    [QCReviewedBy] => bb 
                    [QCWitnessedBy] => cc 
                    [QC1JobPanelId] => 293 
                    [QCTestCompletionDate] => 2016-07-29 00:00:00 
                    [QC1DateAdded] => 2016-07-29 
                ) 
           )
        ) 

也无法从$data['getTestData']获取价值:
试过:

  1. $data['getTestData'][0]['TestDesc']
  2. $data['getTestData'][0][0]['TestDesc']
  3. $data['getTestData']['TestDesc']

2 个答案:

答案 0 :(得分:0)

回答获取$数据,包括来自@Anish&amp;的帮助@Anant:

  • $数据[ 'getTestData'] [0] - &GT; TestDesc
  • ResultVariable [Array1] [Array2] - &gt;对象变量

简而言之:   - 如果是Array,则使用[]
  - 如果是Object,则使用 - &gt;

答案 1 :(得分:0)

是的,访问对象有错误

let jsObj = {
  "oid": "1",
  "oname": "Fon",
  "bun": [{
    "bid": "1",
    "bname": "Ets",
    "dep": [{
      "did": "1",
      "dname": "Dptment",
      "pids": [{
        "pid": "1",
        "st": "active"
      }, {
        "pid": "2",
        "st": "active"
      }]
    }]
  }, {
    "bid": "2",
    "bname": "US",
    "description": "unit2",
    "dep": []
  }]
};

jsObj.bun.filter((b) => {
  return b.bid == 1
});

替换为

$this->db->where($whereField2." = ",$data['get_JobPan_Data'][$i]['QCJobPanelId']);