weixin_33744854 2018-12-11 01:51 采纳率: 0%
浏览 18

显示来自json的数据

I'm trying to show table from json but failed, what's wrong with this:

$nip=$_POST['nip']; 
$sql = "select satker,shift_description,nip  FROM jamkerja 
    inner join master_shift on master_shift.shiftno=jamkerja.shiftno 
    inner join tr_jamkerjahdr on jamkerja.id_jamkerja=tr_jamkerjahdr.id_jamkerja 
    inner join tr_jamkerjamember on tr_jamkerjamember.trno=tr_jamkerjahdr.trno 
    where nip='$nip' ";

$result = $con->query($sql);

$data = array();
while($row = mysqli_fetch_assoc($result)){
    $data[] = $row;
}
print $data;

And this is the table:

$json = $data;
$json_decoded = json_decode($json);
foreach($json_decoded as $data12){
    echo '<tr>';
    echo '<td>'.$data12[satker].'</td>';
    echo '<td>'.$data12[shift_description].'</td>';
    echo '<td>'.$data12[nip].'</td>';
    echo '</tr>';

}
  • 写回答

2条回答 默认 最新

  • weixin_33734785 2018-12-11 02:05
    关注

    Not sure I fully understand your question. But let me try to help you. I think your issue is around

    $json = $data;
    $json_decoded = json_decode($json);
    

    json_decode() is not needed here, the $data that you are assigning to $json is a type array. With the code you shared, I don't see any need for Json, you should directly loop through your $data.

    Hope that helps.

    评论

报告相同问题?