从php/mysql获取日期和时间格式的数据,并应在android studio的textview中显示

从php/mysql获取日期和时间格式的数据,并应在android studio的textview中显示,php,android,mysql,Php,Android,Mysql,我需要从我的sql数据库中获取日期和时间格式的scheduleDate,StartTime,Endtime,Hours,我需要在Android Studio的文本视图中显示它们。但是我无法在文本视图中显示它们。请任何人帮助我 你的代码很好。用户名selva在MySql 因此,尝试使用用户名surya登录,这可能会返回您想要的响应 或 通过用户selva在MySql上添加scheduleDate、StartTime和Endtime数据,您得到了什么错误?共享您的日志您可以使用改装或截取进行res

我需要从我的sql数据库中获取日期和时间格式的
scheduleDate
StartTime
Endtime
Hours
,我需要在Android Studio的文本视图中显示它们。但是我无法在
文本视图中显示它们。请任何人帮助我


你的代码很好。用户名selva
MySql

因此,尝试使用用户名surya登录,这可能会返回您想要的响应


通过用户selva
MySql

上添加scheduleDate、StartTime和Endtime数据,您得到了什么错误?共享您的日志您可以使用改装或截取进行rest api调用,并通过从json检索到pojo formatRamesh Sambu来显示您的数据,先生,我没有收到任何错误,我能够收到名称,密码和电子邮件,但无法从数据库中获取集合数据的日期和时间。@selvas您在响应
ScheduleDate
中是否得到空值?啊,非常感谢您,先生。它在工作。这个帖子有一票否决票(-1),所以我只是问为什么!我不知道是谁干的。先生,我只是点击了勾号,因为我得到了答案。我是新来的。错了吗?嗯,很高兴能帮助你,伙计!
my php code which will fetch the data`
<?php 
error_reporting(0);
require "init.php";

$name = $_POST["name"];
$password = $_POST["password"];

//$name = "sdf";
//$password = "sdf";

$sql = "SELECT * FROM `user_info` WHERE `name`='".$name."' AND `password`='".$password."';";

$result = mysqli_query($con, $sql);

$response = array();

while($row = mysqli_fetch_array($result)){
    $response = array("id"=>$row[0],"name"=>$row[1],"password"=>$row[2],"email"=>$row[3],"ScheduleDate"=>$row[4],"StartTime"=>$row[5],"Endtime"=>$row[6],"Hours"=>$row[7]);
}

echo json_encode(array("user_data"=>$response));

?>
package com.example.myapplication;

import android.content.Context;
import android.content.Intent;
import android.os.AsyncTask;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;

import org.json.JSONException;
import org.json.JSONObject;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;


public class MainActivity extends AppCompatActivity {

    EditText name, password;
    String Name, Password,ScheduleDate,StartTime,Endtime,Hours;
    Context ctx=this;
    String NAME=null, PASSWORD=null, EMAIL=null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        name = (EditText) findViewById(R.id.main_name);
        password = (EditText) findViewById(R.id.main_password);
    }

    public void main_register(View v){
       // startActivity(new Intent(this,Register.class));
    }

    public void main_login(View v){
        Name = name.getText().toString();
        Password = password.getText().toString();
        BackGround b = new BackGround();
        b.execute(Name, Password);
    }

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

        @Override
        protected String doInBackground(String... params) {
            String name = params[0];
            String password = params[1];
            String data="";
            int tmp;

            try {
                URL url = new URL("http://localhost/sample/loo/login.php");
                String urlParams = "name="+name+"&password="+password;

                HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
                httpURLConnection.setDoOutput(true);
                OutputStream os = httpURLConnection.getOutputStream();
                os.write(urlParams.getBytes());
                os.flush();
                os.close();

                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: "+e.getMessage();
            } catch (IOException e) {
                e.printStackTrace();
                return "Exception: "+e.getMessage();
            }
        }

        @Override
        protected void onPostExecute(String s) {
            String err=null;
            try {
                JSONObject root = new JSONObject(s);
                JSONObject user_data = root.getJSONObject("user_data");
                NAME = user_data.getString("name");
                PASSWORD = user_data.getString("password");
                EMAIL = user_data.getString("email");

                ScheduleDate = user_data.getString("ScheduleDate");
                StartTime = user_data.getString("StartTime");
                Endtime = user_data.getString("Endtime");
                Hours = user_data.getString("Hours");
            } catch (JSONException e) {
                e.printStackTrace();
                err = "Exception: "+e.getMessage();
            }

            Intent i = new Intent(ctx, Home.class);
            i.putExtra("name", NAME);
            i.putExtra("password", PASSWORD);
            i.putExtra("email", EMAIL);

            i.putExtra("ScheduleDate", ScheduleDate);
            i.putExtra("StartTime", StartTime);
            i.putExtra("Endtime", Endtime);
            i.putExtra("Hours", Hours);

            i.putExtra("err", err);
            startActivity(i);

        }
    }
}`
    package com.example.myapplication;




import android.app.Activity;
        import android.content.Intent;
        import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.TextView;

public class Home extends AppCompatActivity {

    String name, password, email, Err,ScheduleDate,StartTime,Endtime,Hours;
    TextView nameTV, emailTV, passwordTV, err,ScheduleDateTV,StartTimeTV,EndtimeTV,HoursTV;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_home);

        nameTV = (TextView) findViewById(R.id.home_name);
        emailTV = (TextView) findViewById(R.id.home_email);
        passwordTV = (TextView) findViewById(R.id.home_password);

        ScheduleDateTV = (TextView) findViewById(R.id.ScheduleDate);
        StartTimeTV = (TextView) findViewById(R.id.StartTime);
        EndtimeTV = (TextView) findViewById(R.id.Endtime);
        HoursTV = (TextView) findViewById(R.id.Hours);
        err = (TextView) findViewById(R.id.err);

        name = getIntent().getStringExtra("name");
        password = getIntent().getStringExtra("password");
        email = getIntent().getStringExtra("email");
        ScheduleDate = getIntent().getStringExtra("ScheduleDate");
        StartTime = getIntent().getStringExtra("StartTime");
        Endtime = getIntent().getStringExtra("Endtime");
        Hours = getIntent().getStringExtra("Hours");
        Err = getIntent().getStringExtra("err");

        nameTV.setText("Welcome "+name);
        passwordTV.setText("Your password is "+password);
        emailTV.setText("Your email is "+email);
        ScheduleDateTV.setText("your date "+ScheduleDate);
        StartTimeTV.setText("starting time "+StartTime);
        EndtimeTV.setText("ending time "+Endtime);
        HoursTV.setText("total hours "+Hours);

        err.setText(Err);
    }
}