简体   繁体   中英

No response from database query as JSON

I want to get an array of articles that are liked by the current user that's logged in but I don't get any response from my server. I am doing a http post with userId set that will be used in my query that I'm using to get liked articles by that specific user. My query is as following:

SELECT *, (CASE likes.userId WHEN $userId THEN 1 END) AS liked FROM article INNER JOIN likes on likes.articleId = article.id WHERE likes.userId = '$userId'

I do get the userId from the http post in my PHP file but somehow I get the feeling that the query isn't getting runned by my PHP file.

The code of my PHP file is as following:

require "dbconnect.php";

$data = file_get_contents("php://input");

if(isset($data))
{
$request = json_decode($data);

$userId = $request->userId;
}

$sql = "SELECT *, (CASE likes.userId WHEN '$userId' THEN 1 END) AS liked         FROM article INNER JOIN likes on likes.articleId = article.id WHERE likes.userId    = '$userId'";

$result = mysqli_query($con,$sql);

while($row = mysqli_fetch_array($result))
{
$likedata[] = $row;
}

$count = mysqli_num_rows($result);

if($count > 0)
{
echo json_encode($likedata);
}

Thanks,

Try this json_encode($likedata,JSON_UNESCAPED_UNICODE); It may due to non-utf8 encoded characters

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM