I'm sorry my english is bad, I can't speak english well. I want to make randomize question. On my layout there's an imageView and a button. An imageView will replace with a question which located in my server, and a button for the next question. I made randomize question in my php. But everytime I clicked next Button, some question showing again, it's because everytime I clicked next Button, it will execute the randomize php. My question is, how to make next button without execute randomize php ?
It's my php code :
<?php
$host="localhost";
$username="root";
$password="";
mysql_connect($host,$username,$password);
$database_name="db_ipa";
mysql_select_db($database_name);
$arr = array();
$q = mysql_query("select * from biologi order by rand() limit 10");
while ($row = mysql_fetch_assoc($q)) {
$temp = array(
"no" => $row['no'],
"soal"=>$row['soal'],
);
array_push($arr, $temp);
}
$data = json_encode($arr);
$data = str_replace("\\", "", $data);
echo "$data";
?>
It's my onClick method :
public void next(View v){
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
JSONParser jParser = new JSONParser();
String url ="http://ift.tt/1FGsdAi";
String json = jParser.makeHttpRequestPOSTNew(url);
Log.d("json", json);
ImageView img1 = (ImageView) findViewById(R.id.imageView1);
try {
JSONArray jArray = new JSONArray(json);
StringBuffer str[] = new StringBuffer[jArray.length()];
for(int i=0;i<=10;i++){
if(i==10){
Intent intent = new Intent(getApplicationContext(), Nilai.class);
startActivity(intent);
}
str[i] = new StringBuffer();
JSONObject soal = jArray.getJSONObject(i);
String sSoal = soal.getString("soal");
img1.setImageBitmap(BitmapFactory.decodeStream((InputStream) new URL("http://ift.tt/1J6B6XW" + sSoal).getContent()));
}
} catch (Exception e) {
// TODO: handle exception
}
}
Aucun commentaire:
Enregistrer un commentaire