douhuang9886
2019-07-06 00:50
浏览 535
已采纳

为什么JSON没有显示数据

Error when using some.php?id=$id

I have table named tb_syarat_layanan. When I try to get JSON, array it shows no Data.

<?php

 //Importing database
 require_once('koneksi.php');

 $query = "select * from tb_syarat_layanan WHERE id_layan=$id";
 $hasil = mysqli_query($con,$query);

 if(mysqli_num_rows($hasil) > 0 )
 {
     $response = array();
     $response["data"] = array();
     while($x = mysqli_fetch_array($hasil)) 
     {
         $h['id_layan'] = $x["id_layan"];     
         $h['dokumen'] = $x["dokumen"];
         array_push($response["data"], $h);
     }
     echo json_encode($response);
 }
 else 
 {
     $response["message"] = "No Data";
     echo json_encode($response);
 }

?>

But when I set my $query like this :

$query = "select * from tb_syarat_layanan WHERE id_layan=1";

it show the data that I want

JSON shows no data when $query is set with variable $id

图片转代码服务由CSDN问答提供 功能建议

使用 some.php时出错?id = $ id

我有一个名为 tb_syarat_layanan 的表。 当我尝试获取JSON时,数组显示没有数据。

 &lt;?php 
 
 //导入数据库
 require_once('koneksi.php');  
 
 $ query =“select * from tb_syarat_layanan WHERE id_layan = $ id”; 
 $ hasil = mysqli_query($ con,$ query); 
 
 if if(mysqli_num_rows($ hasil)&gt; 0)
  {
 $ response = array(); 
 $ response [“data”] = array(); 
 while($ x = mysqli_fetch_array($ hasil))
 {
 $ h ['id_layan'] =  $ X [ “id_layan”];  
 $ h ['dokumen'] = $ x [“dokumen”]; 
 array_push($ response [“data”],$ h); 
} 
 echo json_encode($ response); 
} \  n else 
 {
 $ response [“message”] =“No Data”; 
 echo json_encode($ response); 
} 
 
?&gt; 
   \  n 
 

但是当我设置我的$查询时:

  $ query =“select * from tb_syarat_layanan WHERE id_layan = 1”; 
    
 
 

它显示我想要的数据

当使用变量 $ id <设置$ query时,JSON显示无数据 / p>

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • dsqbkh3630 2019-07-06 01:08
    已采纳

    The problem is how you are getting the id from the URL. Data sent on query string are stored inside $_GET

    $id = $_GET['id'];
    $query = "SELECT * FROM tb_syarat_layanan WHERE id_layan = $id";
    
    评论
    解决 无用
    打赏 举报
  • 查看更多回答(1条)

相关推荐 更多相似问题