gpt4 book ai didi

php - 随机生成问题在 Android 应用程序中不起作用

转载 作者:行者123 更新时间:2023-11-29 18:27:57 25 4
gpt4 key购买 nike

已回答的问题:

enter image description here

问题:

enter image description here

我有这些表和以下 PHP 脚本

if($_SERVER['REQUEST_METHOD'] == 'GET') {


//makes it work
$category = (string)filter_input(INPUT_GET, 'category');
$game_id = (string)filter_input(INPUT_GET, 'game_id');

require_once('dbConnect.php');

$query = "SELECT question FROM questions
WHERE category = '$category'
and question
NOT IN
(SELECT question
FROM answered_questions
WHERE game_id='$game_id')ORDER BY Rand() limit 1";

$r = (mysqli_query($con, $query));

$res = mysqli_fetch_array($r);

$result = array();

array_push($result, array(
"question" => $res['question'],
)
);

echo json_encode(array("result" => $result));

mysqli_close($con);

}

一切正常,直到我在 Android 中运行该应用程序。当我单击 getQuestion 按钮/调用该方法时,应用程序会生成已回答的问题。该应用程序旨在每次点击时生成一个不在已回答问题表中的问题

private void getQuestion() {

String url ="";

String cat = category.getText().toString();
String id = game_id.getText().toString();

if (cat.equals("Control Questions")){
url = "http://192.168.0.20/Articulate/getControlQuestion.php?game_id="+id;
}else {
url = "http://192.168.0.20/Articulate/getQuestion.php?category="+cat+"&game_id="+id;
}

StringRequest stringRequest = new StringRequest(url, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
showJSON(response);
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
}
});

RequestQueue requestQueue = Volley.newRequestQueue(this);
requestQueue.add(stringRequest);
}

private void showJSON(String response){
String ques="";
try {
JSONObject jsonObject = new JSONObject(response);
JSONArray result = jsonObject.getJSONArray(Config.JSON_ARRAY);
JSONObject collegeData = result.getJSONObject(0);
ques = collegeData.getString("question");
} catch (JSONException e) {
e.printStackTrace();
}
question.setText(ques);
}

最佳答案

为什么不简单地合并两个表并添加一个 bool (tinyint)字段answered?那么您只需将 SQL 请求更改为 SELECT Question FROM questions WHERE Category = '$category' AND Answer = 0

关于php - 随机生成问题在 Android 应用程序中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45998066/

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