No response from database query as JSON












0















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,










share|improve this question























  • echo the query $sql and then exit; and check whether you are getting specific query value

    – Chris shi
    Nov 21 '18 at 12:10











  • @Chrisshi I ran the query multiple times in the database itself aswell with my own userId and it shows my liked articles and this is the output I get picture

    – Batuhan Beyogullari
    Nov 21 '18 at 12:13













  • print the likedata array and check whether the query is returning any value

    – Chris shi
    Nov 21 '18 at 12:33











  • @Chrisshi I printed the array and all it returns is this imgur.com/a/EfAWPdX

    – Batuhan Beyogullari
    Nov 26 '18 at 10:18











  • Can you remove the if($count > 0) { } condition and just echo json_encode($likedata);

    – Chris shi
    Nov 26 '18 at 10:57
















0















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,










share|improve this question























  • echo the query $sql and then exit; and check whether you are getting specific query value

    – Chris shi
    Nov 21 '18 at 12:10











  • @Chrisshi I ran the query multiple times in the database itself aswell with my own userId and it shows my liked articles and this is the output I get picture

    – Batuhan Beyogullari
    Nov 21 '18 at 12:13













  • print the likedata array and check whether the query is returning any value

    – Chris shi
    Nov 21 '18 at 12:33











  • @Chrisshi I printed the array and all it returns is this imgur.com/a/EfAWPdX

    – Batuhan Beyogullari
    Nov 26 '18 at 10:18











  • Can you remove the if($count > 0) { } condition and just echo json_encode($likedata);

    – Chris shi
    Nov 26 '18 at 10:57














0












0








0








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,










share|improve this question














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,







php http ionic-framework






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 21 '18 at 11:58









Batuhan BeyogullariBatuhan Beyogullari

33




33













  • echo the query $sql and then exit; and check whether you are getting specific query value

    – Chris shi
    Nov 21 '18 at 12:10











  • @Chrisshi I ran the query multiple times in the database itself aswell with my own userId and it shows my liked articles and this is the output I get picture

    – Batuhan Beyogullari
    Nov 21 '18 at 12:13













  • print the likedata array and check whether the query is returning any value

    – Chris shi
    Nov 21 '18 at 12:33











  • @Chrisshi I printed the array and all it returns is this imgur.com/a/EfAWPdX

    – Batuhan Beyogullari
    Nov 26 '18 at 10:18











  • Can you remove the if($count > 0) { } condition and just echo json_encode($likedata);

    – Chris shi
    Nov 26 '18 at 10:57



















  • echo the query $sql and then exit; and check whether you are getting specific query value

    – Chris shi
    Nov 21 '18 at 12:10











  • @Chrisshi I ran the query multiple times in the database itself aswell with my own userId and it shows my liked articles and this is the output I get picture

    – Batuhan Beyogullari
    Nov 21 '18 at 12:13













  • print the likedata array and check whether the query is returning any value

    – Chris shi
    Nov 21 '18 at 12:33











  • @Chrisshi I printed the array and all it returns is this imgur.com/a/EfAWPdX

    – Batuhan Beyogullari
    Nov 26 '18 at 10:18











  • Can you remove the if($count > 0) { } condition and just echo json_encode($likedata);

    – Chris shi
    Nov 26 '18 at 10:57

















echo the query $sql and then exit; and check whether you are getting specific query value

– Chris shi
Nov 21 '18 at 12:10





echo the query $sql and then exit; and check whether you are getting specific query value

– Chris shi
Nov 21 '18 at 12:10













@Chrisshi I ran the query multiple times in the database itself aswell with my own userId and it shows my liked articles and this is the output I get picture

– Batuhan Beyogullari
Nov 21 '18 at 12:13







@Chrisshi I ran the query multiple times in the database itself aswell with my own userId and it shows my liked articles and this is the output I get picture

– Batuhan Beyogullari
Nov 21 '18 at 12:13















print the likedata array and check whether the query is returning any value

– Chris shi
Nov 21 '18 at 12:33





print the likedata array and check whether the query is returning any value

– Chris shi
Nov 21 '18 at 12:33













@Chrisshi I printed the array and all it returns is this imgur.com/a/EfAWPdX

– Batuhan Beyogullari
Nov 26 '18 at 10:18





@Chrisshi I printed the array and all it returns is this imgur.com/a/EfAWPdX

– Batuhan Beyogullari
Nov 26 '18 at 10:18













Can you remove the if($count > 0) { } condition and just echo json_encode($likedata);

– Chris shi
Nov 26 '18 at 10:57





Can you remove the if($count > 0) { } condition and just echo json_encode($likedata);

– Chris shi
Nov 26 '18 at 10:57












1 Answer
1






active

oldest

votes


















0














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






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53411572%2fno-response-from-database-query-as-json%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














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






    share|improve this answer




























      0














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






      share|improve this answer


























        0












        0








        0







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






        share|improve this answer













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







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 26 '18 at 12:32









        Chris shiChris shi

        1531111




        1531111
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53411572%2fno-response-from-database-query-as-json%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Biblatex bibliography style without URLs when DOI exists (in Overleaf with Zotero bibliography)

            ComboBox Display Member on multiple fields

            Is it possible to collect Nectar points via Trainline?