Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在PHP中,我从mySQL编码了一个JSON数组,如何使用它?解码_Php_Mysql_Json - Fatal编程技术网

在PHP中,我从mySQL编码了一个JSON数组,如何使用它?解码

在PHP中,我从mySQL编码了一个JSON数组,如何使用它?解码,php,mysql,json,Php,Mysql,Json,这是我的输出: $sql = "SELECT * FROM `scripts` LIMIT 0, 30 "; $result = mysql_query($sql) or die ('Error updating database: ' . mysql_error()); $json = array(); if(mysql_num_rows($result)) { while($row=mysql_fetch_row($result)) { $json['t

这是我的输出:

$sql = "SELECT * FROM `scripts` LIMIT 0, 30 ";   
$result = mysql_query($sql) or die ('Error updating database: ' . mysql_error()); 
$json = array(); 
if(mysql_num_rows($result)) { 
    while($row=mysql_fetch_row($result)) { 
        $json['table data'][]=$row;
    } 
 } 
$encoded = json_encode($json); 
echo $encoded; 
如何访问阵列的单个部分,它是一个阵列阵列?我要先解码吗?

试着解码

{"table data":[["1","test","30","13"],["2","test2","40","14"]]}
再见

您使用的

$json = '{"foo-bar": 12345}';

$obj = json_decode($json);
print $obj->{'foo-bar'}; // 12345
其中,$id是要访问的行

比如说

 $json['table data'][$id]

在向数组中添加数据时,创建数组

$json['table data'][0][1]  == "test"
$json['table data'][1][1]  == "test2"

你想在哪里使用它?为什么要首先对它进行编码?欢迎来到堆栈溢出!在旁注上;在新代码中。它们不再得到维护,而是在使用。看到红色的盒子了吗?而是学习准备好的语句,并使用或。
$json['table data'][] = array($row);