Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/video/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在ClikListener上生成不重复的随机数据_Php_Android_Random - Fatal编程技术网

Php 如何在ClikListener上生成不重复的随机数据

Php 如何在ClikListener上生成不重复的随机数据,php,android,random,Php,Android,Random,我想随便问一个问题。在我的布局上有一个imageView和一个按钮。imageView将替换为位于我的服务器中的问题和下一个问题的按钮。我在PHP中提出了随机问题。但每次我点击下一个按钮,一些问题再次出现,这是因为每次我点击下一个按钮,它将执行随机PHP。我的问题是,如何在不执行随机PHP的情况下创建next按钮 这是我的PHP代码: <?php $host="localhost"; $username="root"; $password=""; mysql_connect($host,

我想随便问一个问题。在我的布局上有一个imageView和一个按钮。imageView将替换为位于我的服务器中的问题和下一个问题的按钮。我在PHP中提出了随机问题。但每次我点击下一个按钮,一些问题再次出现,这是因为每次我点击下一个按钮,它将执行随机PHP。我的问题是,如何在不执行随机PHP的情况下创建next按钮

这是我的PHP代码:

<?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";
?>

PHP肯定会返回随机结果,您确定getContent行返回的内容正确吗?这仅仅是一个图像URL,还是在服务器端运行更多代码?检查服务器日志以检查请求是否每次都发送到服务器。可能响应正在缓存到某个位置。
public void next(View v){
    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
    StrictMode.setThreadPolicy(policy);
    JSONParser jParser = new JSONParser();
    String url ="http://192.168.137.1/server/soal.php";
    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://192.168.137.1/server/" + sSoal).getContent()));

        }


    } catch (Exception e) {
        // TODO: handle exception
    }
}