Javascript Json编码php mysql查询

Javascript Json编码php mysql查询,javascript,php,jquery,mysql,json,Javascript,Php,Jquery,Mysql,Json,我的代码中有$json变量的问题。出于某种原因,我的php查询没有被编码到$json变量中 $sql = "SELECT `$column`, `Year`, `Month` FROM unemployed WHERE year BETWEEN ? AND ? and month= ?"; $stmt = $conn->stmt_init(); $stmt->prepare($sql); $stmt->bind_param('sss', $gYear, $gYear2, $

我的代码中有$json变量的问题。出于某种原因,我的php查询没有被编码到$json变量中

$sql = "SELECT `$column`, `Year`, `Month` FROM unemployed WHERE year BETWEEN ? AND ? and month= ?";

$stmt = $conn->stmt_init();
$stmt->prepare($sql); 
$stmt->bind_param('sss', $gYear, $gYear2, $gMonth);
$stmt->bind_result($Column, $year, $month);
$stmt->execute();
$stmt->store_result();
$numRows = $stmt->num_rows;
$json = array();

if ($numRows) { ?>

<table>
<tr>
<th scope="col"> Hi </th>
<th scope="col"> Year </th>
<th scope="col"> Month </th>
</tr>

<?php while ($row = $stmt->fetch()) { ?>
<tr>
<td> <?php echo $Column; ?> </td>
<td> <?php echo $year; ?> </td>
<td> <?php echo $month; ?> </td>
</tr> 
$json['unemployed'][]= $row;
<?php } ?>
</table>
<?php
echo json_encode($json);
var_dump($json);
?>
$sql=“选择“$column`、`Year`、`Month`”,其中Year介于?和?之间,Month=?”;
$stmt=$conn->stmt_init();
$stmt->prepare($sql);
$stmt->bind_param('sss',$gYear,$gYear2,$gMonth);
$stmt->bind_result($Column,$year,$month);
$stmt->execute();
$stmt->store_result();
$numRows=$stmt->num_行;
$json=array();
如果($numRows){?>
你好
年
月
$json['unemployee'][=$row;

运行此脚本后,我的$json变量中仍然没有任何内容。有人知道这是为什么吗?该变量现在是否应该是一个带有我的查询值的数组(每一行现在都是数组的一部分)?

问题是,在尝试解析PHP代码时,您超出了PHP解释器的范围

</tr> 
$json['unemployed'][]= $row;

$json['unemployee'][=$row;


它看起来甚至不像

$json['unemployed'][]= $row;
在php标记中

另外,fetch()似乎返回布尔值。当调用fetch()时,它似乎用行中的值填充变量$Column、$year和$month。因此

$json['unemployed'][]= $row;
这样做:

$json['unemployed'][]= array($Column, $year, $month);

这就是我得到的:$json['Underable'][]=$row;$json['Underable'][]=$row;echo json_encode($json);var_dump($json);现在我得到了这个:(var_dump就是这个){“Undered”:[true]}数组(1){[“Undered”]=>array(1){[0]=>bool(true)}是的,那是以前的错误。除了现在我不相信我得到的是正确的。下面是var_dump现在是:{“失业”:[true]}array(1){[“失业”]=>array(1){[0]=>bool(true)}@user2562125你期望得到什么样的输出?类似于{“失业”:[[183000”,“1992”,“一月”],[175000”,“1993”,“一月”]}看起来这个函数返回True/false,那么我可以用什么来代替$stmt->fetch?
$json['unemployed'][]= array($Column, $year, $month);