首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用参数解析json

使用参数解析json
EN

Stack Overflow用户
提问于 2014-03-21 01:01:13
回答 1查看 76关注 0票数 0

嗨,我有这个web服务,我想用afnetworking的参数调用它

代码语言:javascript
复制
<?php
header('Content-Type: application/json; charset=utf-8');
include('settings.php');
mysql_connect($host,$user,$password);
mysql_select_db($base);
mysql_query('SET CHARACTER SET utf8');
$patient = (int) $_POST['patient'];

$req = "select * from consultation where id_patient= $patient";
$sql=mysql_query($req);
$nn=mysql_num_rows($sql);

$items = array("items" => NULL);

while ($data=mysql_fetch_array($sql))
{
    $items["items"][] = array(
        "id_consultation" => $data['id_consultation'],
        "id_patient" => $data['id_patient'],
        "date_consultation" => $data['date_consultation'],
        "motif_consultation" => $data['motif_consultation'],
        "taille" => $data['taille'],
        "poids" => $data['poids'],
        "tension_arterielle" => $data['tension_arterielle'],
        "pouls" => $data['pouls'],
        "temperature" => $data['temperature'],
        "observation" => $data['observation'],
        "ordonnance" => $data['ordonnance'],

    );


}
    echo json_encode($items,JSON_UNESCAPED_UNICODE);

?>

当我用

代码语言:javascript
复制
http://localhost:8888/services/consultation.php?patient=1

它显示{“items”:空}是否有人可以帮助我:) thx

EN

回答 1

Stack Overflow用户

发布于 2014-03-21 01:16:03

代码语言:javascript
复制
$items = array("items" => array());

while ($data=mysql_fetch_array($sql))
{
    $item = array(
        "id_consultation" => $data['id_consultation'],
        "id_patient" => $data['id_patient'],
        "date_consultation" => $data['date_consultation'],
        "motif_consultation" => $data['motif_consultation'],
        "taille" => $data['taille'],
        "poids" => $data['poids'],
        "tension_arterielle" => $data['tension_arterielle'],
        "pouls" => $data['pouls'],
        "temperature" => $data['temperature'],
        "observation" => $data['observation'],
        "ordonnance" => $data['ordonnance']
        );

    array_push($items['items'], $item);
}

echo json_encode($items);

试一试

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22540118

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档