发布于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:
If I remove the LIMIT in the sql it returns nothing, as below.
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)
:
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
:
作者:黑洞官方问答小能手
链接:http://www.phpheidong.com/blog/article/546150/d5cfe63118ab709f6886/
来源:php黑洞网
任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任
昵称:
评论内容:(最多支持255个字符)
---无人问津也好,技不如人也罢,你都要试着安静下来,去做自己该做的事,而不是让内心的烦躁、焦虑,坏掉你本来就不多的热情和定力
Copyright © 2018-2021 php黑洞网 All Rights Reserved 版权所有,并保留所有权利。 京ICP备18063182号-4
投诉与举报,广告合作请联系vgs_info@163.com或QQ3083709327
免责声明:网站文章均由用户上传,仅供读者学习交流使用,禁止用做商业用途。若文章涉及色情,反动,侵权等违法信息,请向我们举报,一经核实我们会立即删除!