dory4404 2013-11-15 23:11 采纳率: 0%
浏览 37
已采纳

了解数据库表的JSON输出

I'm new to JSON and I am writing a PHP script to take all the data from a remote MySQL db to import to a ios sqlite database. My plan is to take all the tables from each database and send it to the other and check if the rowid are in the right table, if it is, throw it out, if not add it to that database, basically adding whatever rows aren't in the database to it.

I am trying to read my JSON output from the remote MySql server and I dont quite understand it and can't find any good resources. For my login table I pull it like this:

$query = "SELECT * from answers";
$result = $this->db->query($query) or die('Errant query:  '.$query);

$answers = array();
$answers=mysqli_fetch_array($result);
header('Content-type: application/json');
echo json_encode(array(
'login'=>$login,
'answers'=>$answers,
'projects'=>$projects,
'questions'=>$questions,
'surveys'=>$surveys,
 ));

Then when I read the output it shows for the login table:

  {"login":{"0":"1","userid":"1","1":"test","password":"test","2":"1","aclevel":"1"},

The login table has three columns: userid, password, and aclevel. Filled in this table is 1, test, 1 respectively.

Can someone explain to me what the output of the JSON means?

  • 写回答

1条回答 默认 最新

  • duanqiaoren9975 2013-11-15 23:17
    关注

    See the docs for mysql_fetch_array.

    It returns an array with both numeric and field index if the second parameter is missing. This generates an array like this:

    array (
        'field1' => value1,
        0 => value1,
        'field2' => value2,
        1 => value2,
        ...
    )
    

    Use:

    mysql_fetch_array($result, MYSQL_ASSOC);
    // OR...
    mysql_fetch_assoc($result);
    

    To retrieve data and see what happens.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的