duanfan8360 2018-11-18 22:05
浏览 46

从数据库获取用户注册日期并发送到android

i have problem in my app i have a users table in my database with 3 columns, now i want to get the user registering time from my database(server) and send to my app, and it showed in user profile(as dialog) in the app. its my php code :

function get(){

$connection = connectToDatabase();
$Username = $_REQUEST['Username'];
$Pass = $_REQUEST['Pass'];


if($Username!="" && $Pass!=""){

        $result = mysqli_query($connection,"select Date from users where Username='$Username' and Pass='$Pass');


    $array_finish = array();
    while($row = mysqli_fetch_array($result)){

        $record = array();
        $record['Date'] = $row['Date'];
        $array_finish[] = $record ;
    }

    echo json_encode($array_finish);

}else {
    print "null";
}
mysqli_close($connection); }

but i have some error in this codes and i dont know how i can get this information in my app. i know my codes in android isn't correct it's my android codes:

 private void ShowProfile(){

    profile = new MaterialDialog.Builder(MainActivity.this)
            .customView(R.layout.alert_aprofile,false)
            .show();

    AsyncHttpPost post = new AsyncHttpPost(
            "http://********/profile.php"
    );

    post.setTimeout(5000);
    MultipartFormDataBody body = new MultipartFormDataBody();
    body.addStringPart("Username",sp.getString("Username", null));
    body.addStringPart("Pass",sp.getString("Pass", null));
    post.setBody(body);

    AsyncHttpClient.getDefaultInstance().executeString(post, new AsyncHttpClient.StringCallback() {
                @Override
                public void onCompleted(final Exception e, AsyncHttpResponse source, final String row) {

                    if (e != null) {
                        MainActivity.this.runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                              wait.dismiss();
                                Toast.makeText(MainActivity.this, "no connection", Toast.LENGTH_LONG).show();
                                e.printStackTrace();
                            }
                        });
                    }

                    if (!row.equals("")) {
                        profile_time = (TextView)profile.findViewById(R.id.profile_time);
                        profile_time.setText(row);
                    }else if(row.equals("null")){

                        runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                wait.dismiss();
              ;
                            }
                        });

                    }
                }
});

please help me to correcting that..

i edit android code to new code but i know it isnt correct and dont work...

 private void ShowProfile(){

    profile = new MaterialDialog.Builder(MainActivity.this)
            .customView(R.layout.alert_aprofile,false)
            .show();

    AsyncHttpPost post = new AsyncHttpPost(
            "http://****************profile.php"
    );

    post.setTimeout(5000);
    MultipartFormDataBody body = new MultipartFormDataBody();
    body.addStringPart("Username",sp.getString("Username", null));
    body.addStringPart("Pass",sp.getString("Pass", null));
    post.setBody(body);

    AsyncHttpClient.getDefaultInstance().executeString(post, new AsyncHttpClient.StringCallback() {
                @Override
                public void onCompleted(final Exception e, AsyncHttpResponse source, final String result) {

                    if (e != null) {
                        MainActivity.this.runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                wait.dismiss();
                                Toast.makeText(MainActivity.this, "no connection", Toast.LENGTH_LONG).show();
                                e.printStackTrace();
                            }
                        });
                    }


                    if (!result.equals("")) {
                        MainActivity.this.runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                items.clone();
                                try {
                                    JSONArray jsonArray = new JSONArray(result);
                                    for (int i = 0; i < jsonArray.length(); i++) {
                                        JSONObject object = jsonArray.getJSONObject(i);
                                        HashMap<String, Object> hash_add = new HashMap<String, Object>();

                                        hash_add.put("Date", object.getString("Date"));

                                        hash_all.add(hash_add);
                                        items = new String[hash_all.size()];
                                    }

                                } catch (Exception e) {
                                    e.printStackTrace();
                                }
                            }
                        });
                    }
                }

});
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 微信小程序协议怎么写
    • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
    • ¥20 怎么用dlib库的算法识别小麦病虫害
    • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
    • ¥15 java写代码遇到问题,求帮助
    • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
    • ¥15 有了解d3和topogram.js库的吗?有偿请教
    • ¥100 任意维数的K均值聚类
    • ¥15 stamps做sbas-insar,时序沉降图怎么画
    • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看