drpp5680 2016-07-11 06:31 采纳率: 0%
浏览 54

从php调用数组

If i want to call an array from php into typescript also in an array form how i can do it this is my php code :

$AccessQuery = "SELECT name,lastname,phone,email
                      FROM user
                     INNER JOIN access ON id

                     WHERE id 
$userQuery = mysqli_query($localhost, $AccessQuery) or trigger_error(mysql_error(), E_USER_ERROR);
while ($AccessQueryRow = mysqli_fetch_assoc($userQuery)) {
    $AccessData[] = array(
        'id' => $AccessQueryRow['id'],
        'code' => $AccessQueryRow['code'],

    );
};

$arr = array(

    "user_access_details" => $AccessData,

);
echo json_encode($arr);

I try this in order to encoded and use each one as a variable in an array

 var jsonData = JSON.parse(data);

what i really want is how i can put each menu_id in an array field : arr= {id1,id2} the same for the code

  • 写回答

1条回答 默认 最新

  • dongyi6543 2016-07-11 06:39
    关注

    how i can put each menu_id in an array field : arr= {id1,id2}

    If you only care about the ids, ignore the code values. Get the array of the shape you want in PHP.

    while ($AccessQueryRow = mysqli_fetch_assoc($userQuery)) {
        $AccessData[] = $AccessQueryRow['id'];
    };
    
    echo json_encode($AccessData);
    

    On the client side:

    var jsonData = JSON.parse(data);
    

    The result will be the array of just ids.

    评论

报告相同问题?

悬赏问题

  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)