本站消息

站长简介/公众号

  出租广告位,需要合作请联系站长

+关注
已关注

分类  

暂无分类

标签  

暂无标签

日期归档  

暂无数据

No JSON returned in Postman if the number of rows exceeds 15

发布于2023-05-25 21:34     阅读(297)     评论(0)     点赞(9)     收藏(0)


I have a REST API which is written to fetch the questions and answers data for a quiz app that we are working on, and the sql am using is as follows in the API file. I have set the limit as (LIMIT 0,15) as if I change that to 16 there is no data returned by postman. Below are the screenshots for the same.

<?php

include('config.php');

 if (isset($_SERVER['HTTP_ORIGIN'])) {
    header("Access-Control-Allow-Origin: {$_SERVER['HTTP_ORIGIN']}");
    header('Access-Control-Allow-Credentials: true');
    header('Access-Control-Max-Age: 86400');    // cache for 1 day
}

// Access-Control headers are received during OPTIONS requests
if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {

    if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_METHOD']))
        header("Access-Control-Allow-Methods: GET, POST, OPTIONS");         

    if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']))
        header("Access-Control-Allow-Headers:
 {$_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']}");

    exit(0);
  }

 $postdata = file_get_contents("php://input");
 if (isset($postdata)) 
 {
    $request = json_decode($postdata);

    $SubID = $request->SubID;

    if( isset($SubID) ) {
        $select_sql = "SELECT * FROM `questions` WHERE `subjectid` = 
   '".$SubID."'";

        $select_query = mysqli_query($con,$select_sql);
        $count = mysqli_num_rows($select_query);
        if($count>0) {
            while($fetch_obj = mysqli_fetch_array($select_query 
 ,MYSQLI_BOTH)) {

                    $SubId = $fetch_obj["subjectid"];
                    $QuestId = $fetch_obj["questionid"];
                    $QuestType = $fetch_obj["questiontype"];
                    $Quest = $fetch_obj["question"];
                    $Ans1 = $fetch_obj["answer1"];
                    $Ans2 = $fetch_obj["answer2"];
                    $Ans3 = $fetch_obj["answer3"];
                    $Ans4 = $fetch_obj["answer4"];
                    $CorrectAns = $fetch_obj["correctanswer"];
                    $Hint = $fetch_obj["hint"];
                    $DiffLevel = $fetch_obj["difficultylevel"];
                    $Status = $fetch_obj["status"];
                    $AnsDescrip = $fetch_obj["ans_description"];

                    $QuestionsList[] = array( "SubjectID" => "$SubId",
                        "QuestionID" => "$QuestId", 
                        "QuestionType" => "$QuestType", 
                        "Question" => "$Quest",
                        "Answer1" => "$Ans1", 
                        "Answer2" => "$Ans2",
                        "Answer3" => "$Ans3",
                        "Answer4" => "$Ans4",
                        "CorrectAnswer" => "$CorrectAns",
                        "Hint" => "$Hint", 
                        "DiffLevel" => "$DiffLevel",
                        "Status" => "$Status",
                        "AnsDescription" => "$AnsDescrip");

            }
                $json = array("status" => 1, 
                    "message" => "Questions list Successfully fetched", 
                    "QuestionsList" => var_dump($QuestionsList));
               /* foreach ($QuestionsList as $value) {
                    print_r($value);
                }*/
        }
        else {
                $json = array("status" => 0, "message" => "No Records 
Found.", "query" => $select_sql);
        }

    }
}
mysqli_close($con);

header('Content-type: application/json');
echo json_encode($json);

?>

On having the LIMIT 0, 15 in the sql , it returns the data as shown below: enter image description here

If I remove the LIMIT in the sql it returns nothing, as below. enter image description here

Does this have something do with the JSON response data limit in php, if yes where can I change this? And also I have checked in on the production live server as well and it returns the same result. Please help me out on this.

on doing a var_dump($QuestionList) :enter image description here


解决方案


Your query:

$select_sql = "SELECT * FROM `questions` WHERE `subjectid` = 
     '".$SubID."' LIMIT 0, 15";

Without limit:

$select_sql = "SELECT * FROM `questions` WHERE `subjectid` = 
     '".$SubID."'";

In LIMIT 0,15:

  • 0 is the offset of the first row.
  • 15 is the maximum number rows that return from table.


所属网站分类: 技术文章 > 问答

作者:黑洞官方问答小能手

链接:http://www.phpheidong.com/blog/article/546150/d5cfe63118ab709f6886/

来源:php黑洞网

任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任

9 0
收藏该文
已收藏

评论内容:(最多支持255个字符)