gpt4 book ai didi

php - 如果行数超过 15,则 Postman 不返回 JSON

转载 作者:行者123 更新时间:2023-11-30 21:58:33 26 4
gpt4 key购买 nike

我有一个 REST API,用于获取我们正在开发的测验应用程序的问题和答案数据,API 文件中使用的 sql 如下所示。我已将限制设置为(LIMIT 0,15),就好像我将其更改为 16 一样, postman 没有返回任何数据。以下是相同的屏幕截图。

<?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 0, 15 时,它返回如下所示的数据: enter image description here

如果我删除 sql 中的 LIMIT,它什么都不返回,如下所示。 enter image description here

这是否与 PHP 中的 JSON 响应数据限制有关,如果是,我可以在哪里更改它?而且我也检查了生产实时服务器,它返回了相同的结果。请帮我解决这个问题。

在做一个 var_dump($QuestionList): enter image description here

最佳答案

您的查询:

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

没有限制:

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

LIMIT 0,15 中:

  • 0 是第一行的偏移量。
  • 15 是从表中返回的最大行数。

关于php - 如果行数超过 15,则 Postman 不返回 JSON,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44238963/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com