I'm trying to build a JSOn from PHP, but when I put two conditions it does not generate the data.
That is, I only need to bring the data of SARA , but when I put them in id_ppl and level at the same time, I get nothing. I do not really know what I'm doing wrong.
I tried it by postman changing the variables, bring it only by id, or by user and it works, but when I put the previous two I do not get anything.
Table
id | usuario | password | token | id_ppl | nivel | multi |
-------------------------------------------------------------
1 | Juana | ***** | | 1 | 1 | on |
-------------------------------------------------------------
2 | Sara | ***** | | 1 | 2 | on |
-------------------------------------------------------------
PHP Script
require 'conn.php';
if (mysqli_connect_errno()) {
echo "Gagal terhubung MySQL: " . mysqli_connect_error();
}
$id = $_GET["id"];
$nivel = $_GET["nivel"];
$query = mysqli_query($connect, "SELECT id, nivel, multi FROM escolar_users WHERE id_ppl = '$id' AND nivel='$nivel'");
$json = '{"loadUser": [';
while ($row = mysqli_fetch_array($query)){
$char ='"';
$json .=
'{
"id":"'.str_replace($char,''',strip_tags($row['id'])).'",
"nivel":"'.str_replace($char,''',strip_tags($row['nivel'])).'",
"multi":"'.str_replace($char,''',strip_tags($row['multi'])).'"
},';
}
// buat menghilangkan koma diakhir array
$json = substr($json,0,strlen($json)-1);
$json .= ']}';
// print json
echo $json;
mysqli_close($connect);
URL method GET
load.php?id_ppl=1&nivel=2