簡體   English   中英

嘗試獲取字段值時出現“數組到字符串轉換錯誤”

[英]"Array to string conversion error" when trying to get the values of fields

我正在嘗試將數據表作為服務器端處理。 它以某種方式起作用。 我想將字段傳遞給 ajax 文件並使用它們來獲取數據。 我將字段名稱設為字符串以使用分隔符分隔它們。 然后我傳遞了字符串並獲取它並將它們作為一個數組。 問題是,當我嘗試通過它們獲取值時會顯示“數組到字符串轉換錯誤”。

10 月 CMS 中的 PHP 塊

<?php

function onStart()
{
    $this['tableName'] = 'BYAPPS_apps_data';
    $this['fields'] = "app_id|app_name|app_ver|byapps_ver";
}
?>

10 月 CMS 中的 Javascript(與 php 塊相同的頁面)

  var table = $('#' + tableId).DataTable( {
      processing: true,
      serverSide: true,
      ajax: {
          url: '/ajax?tb={{ tableName|raw() }}&fd={{ fields|raw() }}',
          type: 'GET',
          error: function(e) {
            console.log(e);
          }
      },
      paging: true,
      pageLength: 50,

Ajax 頁面

function onStart()
{
   $table = $_GET['tb'];
   $length = $_GET['length'];
   $start = $_GET['start'];
   $fields = explode("|", $_GET['fd']);

   $result = DB::table($table)->skip($start)->limit($length)->get();
   $data = array();

   foreach($result as $row) {
      $sub_array = array();

      for ($i = 0; $i < count($fields); $i++) {

        echo "<script>console.log('".$fields[$i]."')</script>";
        $sub_array[] = $row->$fields[$i];

      }
      $data[] = $sub_array;
   }

$fields[$i]顯示“app_id”、“app_name”……但我不知道為什么我不能像這樣獲取值。 $row->$fields[$i]我該如何解決這個問題?

$result 包含這些類似下面的數據。

object(October\Rain\Support\Collection)#947 (1) { ["items":protected]=> array(50) { [0]=> object(stdClass)#949 (88) { ["idx"]=> int(1) ["o_idx"]=> int(0) ["mem_id"]=> string(20) "epicegirls@naver.com" ["app_id"]=> string(10) "epicegirls" ["recom_id"]=> string(6) "byapps" ["app_cate"]=> string(2) "01" ["app_process"]=> int(8) ["app_name"]=> string(12) "에피스걸" ["service_type"]=> string(3) "biz" ["server_group"]=> string(1) "2" ["apps_type"]=> string(19) "안드로이드+iOS" ["app_os_type"]=> string(7) "android" ["byapps_ver"]=> string(3) "2.1" ["app_ver"]=> string(3) "1.6" ["app_ver_ios"]=> string(3) "1.1" ["app_build"]=> string(0) "" ["app_build_ios"]=> string(0) "" ["app_lang"]=> string(2) "ko" ["packagename"]=> NULL ["bundleid"]=> NULL ["app_android_url"]=> string(66) "http://play.google.com/store/apps/details?id=com.epicegirls.byapps" ["app_ios_url"]=> string(58) "http://itunes.apple.com/kr/app/episeugeol/id648794513?mt=8" ["app_icon"]=> string(14) "1366951826.png" ["noti_gcm"]=> string(39) "AIzaSyB4uXkiTltMx3yjQNo26uyfpopMB8vpd94" ["noti_ios"]=> string(14) "1369015681.pem" ["noti_gcm_num"]=> NULL ["noti_fcm_num"]=> NULL ["noti_ios_cerp"]=> string(10) "byapps2013" ["push_server"]=> string(7) "default" ["developer_account"]=> string(1) "N" ["developer_info"]=> string(2580) "- 개발자아이디: 

嘗試這個

$sub_array[] = $row->{$fields[$i]};

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM