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.

    评论

报告相同问题?

悬赏问题

  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 linux驱动,linux应用,多线程