Php 如何使viewimage动态化?

Php 如何使viewimage动态化?,php,android,mysql,json,imageview,Php,Android,Mysql,Json,Imageview,我试图在android上显示来自mysql数据库的图像。我将我的数据库连接到mysql,它正在网上检索数据,但当我在android上发送数据时,它显示没有输出。 以下是php文件: $con = new mysqli ($server_name, $mysql_user, $mysql_pass, $db_name); if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect

我试图在android上显示来自mysql数据库的图像。我将我的数据库连接到mysql,它正在网上检索数据,但当我在android上发送数据时,它显示没有输出。 以下是
php
文件:

    $con = new mysqli ($server_name, $mysql_user, $mysql_pass, $db_name);
if (mysqli_connect_errno())
  {  echo "Failed to connect to MySQL: " . mysqli_connect_error();}
if (isset($_POST['id'])) {}
$id=(int)$_POST['id'];
$sql = "SELECT c_image FROM images WHERE criminal_criminal_id=$id";
$r_query = $con->query($sql);
$i=0;
while($row = $r_query->fetch_assoc()) {
         $response[$i]=   array( "Match_id"=> $row['image_id'],"image"=>$row["c_image"]);         
         $i++;
         $image=$row['c_image'];
    echo     '<img src="data:image/jpeg;base64,'.base64_encode($row['c_image']).'"/>'; }

 echo json_encode(array("user_data"=>$response));
$con=newmysqli($server\u name、$mysql\u user、$mysql\u pass、$db\u name);
if(mysqli\u connect\u errno())
{echo“无法连接到MySQL:”.mysqli_connect_error();}
如果(isset($_POST['id']){}
$id=(int)$_POST['id'];
$sql=“从犯罪嫌疑人id=$id的图像中选择犯罪嫌疑人图像”;
$r_query=$con->query($sql);
$i=0;
而($row=$r\u query->fetch\u assoc()){
$response[$i]=数组(“Match_id”=>$row['image_id'],“image”=>$row[“c_image”]);
$i++;
$image=$row['c_image'];
回音“;}
echo json_编码(数组(“用户_数据”=>$response));
MainActivity.java

public class MainActivity extends Activity {
    ImageView imageview;
    Button btn;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        BackGround b = new BackGround();
        b.execute();
    }


    class BackGround extends AsyncTask<String ,String, String> {


        @Override
        protected String doInBackground(String... params) {
            String data="";

            int tmp;

            try {
                URL url = new URL("http://192.168.15.60/fetchimage.php");
                HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
                httpURLConnection.setDoOutput(true);

                InputStream is = httpURLConnection.getInputStream();
                while((tmp=is.read())!=-1){
                    data+= (char)tmp;
                }

                is.close();
                httpURLConnection.disconnect();

                return data;
            } catch (MalformedURLException e) {
                e.printStackTrace();
                return "Exception 1: "+e.getMessage();

            } catch (IOException e) {
                e.printStackTrace();
                return "Exception 2: "+e.getMessage();
            }
        }

        protected void onPostExecute(String data) {
            String image="";
            try {

                JSONObject json = new JSONObject(data.toString());
                JSONArray jArray = json.getJSONArray("user_data");
                for (int i = 0; i <= jArray.length(); i++) {
                    JSONObject json_data = jArray.getJSONObject(i);


                   image= json_data.getString("image");


                }

                byte[] rawImage = Base64.decode(image, Base64.DEFAULT);
                Bitmap bmp = BitmapFactory.decodeByteArray(rawImage, 0, rawImage.length);

                imageview= (ImageView) findViewById(R.id.imageView);

                imageview.setImageBitmap(bmp);

            } catch (JSONException e) {
                Log.e("log_tag", "Error parsing data " + e.toString());
            }

        }
    }

}
公共类MainActivity扩展活动{
图像视图图像视图;
按钮btn;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
背景b=新背景();
b、 执行();
}
类后台扩展异步任务{
@凌驾
受保护的字符串doInBackground(字符串…参数){
字符串数据=”;
int tmp;
试一试{
URL=新URL(“http://192.168.15.60/fetchimage.php");
HttpURLConnection HttpURLConnection=(HttpURLConnection)url.openConnection();
httpURLConnection.setDoOutput(true);
InputStream=httpURLConnection.getInputStream();
而((tmp=is.read())!=-1){
数据+=(字符)tmp;
}
is.close();
httpURLConnection.disconnect();
返回数据;
}捕获(格式错误){
e、 printStackTrace();
返回“异常1:+e.getMessage();
}捕获(IOE异常){
e、 printStackTrace();
返回“异常2:+e.getMessage();
}
}
受保护的void onPostExecute(字符串数据){
字符串图像=”;
试一试{
JSONObject json=新的JSONObject(data.toString());
JSONArray jArray=json.getJSONArray(“用户数据”);
对于(int i=0;i
    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/imageView"
        android:layout_alignParentTop="true"
        android:layout_alignParentStart="true"
        android:layout_marginStart="48dp"
        android:layout_marginTop="36dp"
        />
</RelativeLayout>