PHP在URL中使用$ GET过滤json

时间:2016-09-18 18:15:06

标签: php json

我希望我的json在网址中使用$GET过滤两行,我可以输入类似http://carkila.esy.es/carkila/user.php?owner=ownerANDstatus=pending的内容,请你帮我修复代码谢谢。 :)

<?PHP
include_once("connection.php");

session_start();

$where = '';
if (isset($_GET['owner']) && isset($_GET['status'])){
$where = " WHERE owner like '%".addslashes($_GET['owner'])."%' AND status like '%".addslashes($_GET['status'])."%'";
}
$query = "SELECT * FROM tbl_cars ".$where." ORDER BY Car_No DESC"; 

$result = mysqli_query($conn, $query);

while ($row = mysqli_fetch_assoc($result)) {
$data[] = $row;
}
 echo json_encode($data);

?>

1 个答案:

答案 0 :(得分:0)

使用此:owner&status参数分隔符作为网址。

您也可以使用 http_build_query (array('owner'=>'owner','status'=>'pending'))

生成owner=owner&status=pending