使用Android开发测验应用程序 - PHP MySql(DataBase) 它只从数据库中获取最后一行,我想实现并在下次点击时逐个获取数据。
所以它会像测验一样工作
这是最近的代码
protected void onPostExecute(String result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
try
{
JSONObject json_data = new JSONObject(res);
quizID =(json_data.getString("quizID"));
question =(json_data.getString("question"));
choice1 =(json_data.getString("choice1"));
choice2 =(json_data.getString("choice2"));
choice3 =(json_data.getString("choice3"));
answer =(json_data.getString("answer"));
txtno.setText("No. " + quizID);
txtque.setText("" + question);
ropt0.setText("" + choice1);
ropt1.setText("" + choice2);
ropt2.setText("" + choice3);
ranswer.setText("" + answer);
}
catch(Exception e)
{
Log.e("Fail 3", e.toString());
}
}
PHP select.php代码
<?php
$host='localhost';
$uname='root';
$pwd='';
$db="QuizDB";
$con = mysqli_connect($host,$uname,$pwd,$db) or die("connection failed");
$quizID=$_REQUEST['quizID'];
$question=$_REQUEST['question'];
$choice1=$_REQUEST['choice1'];
$choice2=$_REQUEST['choice2'];
$choice3=$_REQUEST['choice3'];
$answer=$_REQUEST['answer'];
$sql = "SELECT * FROM QuizQuestion";
$result = mysqli_query($con, $sql);
while($row=mysqli_fetch_array($result))
{
$flag['quizID']=$row["quizID"];
$flag['question']=$row["question"];
$flag['choice1']=$row["choice1"];
$flag['choice2']=$row["choice2"];
$flag['choice3']=$row["choice3"];
$flag['answer']=$row["answer"];
}
print(json_encode($flag));
mysqli_close($con);
?>
请提出一些解决方案,以及如何实施下一个&amp;以前的功能
答案 0 :(得分:0)
是的,这是因为一旦你拥有了这个标志对象,比如表中的第一条记录,你就不会使用它,只是在下一次执行while循环时用下一条记录中的数据覆盖它
做类似的事情:
while($row=mysqli_fetch_array($result))
{
$flag['quizID']=$row["quizID"];
$flag['question']=$row["question"];
$flag['choice1']=$row["choice1"];
$flag['choice2']=$row["choice2"];
$flag['choice3']=$row["choice3"];
$flag['answer']=$row["answer"];
...send flag object to wherever you want...
}
mysqli_close($con);
要实施逐个点击结果,请为下一步和上一页按钮保留一个单击计数器,当按下其中一个按钮时,发送值到类似的脚本,你可以修改查询,如:
$sql = "SELECT * FROM table ORDER BY quizID LIMIT "+counter+"-1,1";
$result = mysqli_query($con, $sql);
while($row=mysqli_fetch_array($result))
{
$flag['quizID']=$row["quizID"];
$flag['question']=$row["question"];
$flag['choice1']=$row["choice1"];
$flag['choice2']=$row["choice2"];
$flag['choice3']=$row["choice3"];
$flag['answer']=$row["answer"];
}
同样做以前的脚本。好好管理柜台。最初将其初始化为1.即按下一步时,将计数器增加1,按上一步时将计数器减1。