我有一个REST API,用于获取我们正在处理的测验应用程序的问题和答案数据,并且在API文件中使用的sql如下所示。 我已将限制设置为(LIMIT 0,15),就好像我将其更改为16,邮递员没有返回任何数据。以下是相同的屏幕截图。
<?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);
?>
如果我删除了sql中的LIMIT,它将不返回任何内容,如下所示。
这是否与php中的JSON响应数据限制有关,如果是,我可以在哪里更改?而且我也检查了生产实时服务器,它返回相同的结果。 请帮我解决这个问题。
答案 0 :(得分:0)
您的查询:
$select_sql = "SELECT * FROM `questions` WHERE `subjectid` =
'".$SubID."' LIMIT 0, 15";
无限制:
$select_sql = "SELECT * FROM `questions` WHERE `subjectid` =
'".$SubID."'";
在LIMIT 0,15
: