dougou8573 2016-06-28 13:45
浏览 39

来自while循环的JSON编码没有返回任何结果PHP

I am trying to create json response from a database results, the issue i am having is that, if i request one item i get the result as i need it but i am not receiving the collection with the code below.

The data is there i can see it when i do a var_dump.

Here is the code.

        $i = 0;
        while ( $obj = sqlsrv_fetch_array ( $stmt3, SQLSRV_FETCH_ASSOC ) ) {
            $rows [] = array (
                    'Note Id' => $obj ['NoteId'],
                    'Patient Id' => $obj ['PatientID'],
                    'Note Text' => $obj ['NoteText'],
                    'Date of Note' => $obj ['DateOfNote'],
                    'Category Id' => $obj ['CategoryId'] 
            );
            $i ++;
        } 

echo json_encode ( $rows);

Here is an extract from the var_dump

array(27) {
  [0]=>
  array(5) {
    ["Note Id"]=>
    int(66)
    ["Patient Id"]=>
    string(36) "xxxxxxxxxxxxxxxx"
    ["Note Text"]=>
    string(70) "Remember to set "
    ["Date of Note"]=>
    object(DateTime)#4 (3) {
      ["date"]=>
      string(26) "2012-01-30 16:13:04.033000"
      ["timezone_type"]=>
      int(3)
      ["timezone"]=>
      string(13) "Europe/Berlin"
    }
    ["Category Id"]=>
    int(1)
  }
  [1]=>
  array(5) {
  ["Note Id"]=>
    int(67)
    ["Patient Id"]=>
    string(36) "xxxxxxxxxxxxxx"
    ["Note Text"]=>
    string(61) "Keep having"
    ["Date of Note"]=>
    object(DateTime)#5 (3) {
      ["date"]=>
      string(26) "2012-01-30 16:13:52.763000"
      ["timezone_type"]=>
      int(3)
      ["timezone"]=>
      string(13) "Europe/Berlin"
    }
    ["Category Id"]=>
    int(1)
  }
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥100 set_link_state
    • ¥15 虚幻5 UE美术毛发渲染
    • ¥15 CVRP 图论 物流运输优化
    • ¥15 Tableau online 嵌入ppt失败
    • ¥100 支付宝网页转账系统不识别账号
    • ¥15 基于单片机的靶位控制系统
    • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
    • ¥15 手机接入宽带网线,如何释放宽带全部速度