Android将用户名传递给php
我正在构建一个android应用程序,希望用户执行单独分配给他们的某些任务。要下载项目信息,我正在使用Android将用户名传递给php,php,android,arguments,Php,Android,Arguments,我正在构建一个android应用程序,希望用户执行单独分配给他们的某些任务。要下载项目信息,我正在使用HTTPServiceClass,并在我的android应用程序中传递url。代码如下 String getProjectsURL = "http://192.168.0.102/syncsqlite/getProjects.php"; 内部doInBackground我有以下几点 protected Void doInBackground(Void... arg0) {
HTTPServiceClass
,并在我的android应用程序中传递url。代码如下
String getProjectsURL = "http://192.168.0.102/syncsqlite/getProjects.php";
内部doInBackground
我有以下几点
protected Void doInBackground(Void... arg0) {
HttpServiceClass httpServiceClass = new HttpServiceClass(getProjectsURL);
try {
httpServiceClass.ExecutePostRequest();
if (httpServiceClass.getResponseCode() == 200) {
FinalJSonResult = httpServiceClass.getResponse();
if (FinalJSonResult != null) {
JSONArray jsonArray = null;
try {
jsonArray = new JSONArray(FinalJSonResult);
JSONObject jsonObject;
for (int i = 0; i < jsonArray.length(); i++) {
jsonObject = jsonArray.getJSONObject(i);
String projectName = jsonObject.getString("ProjectName");
String projectDescription = jsonObject.getString("ProjectDescription");
String projType = jsonObject.getString("projType");
String projStatus = jsonObject.getString("projectStatus");
String SQLiteDataBaseQueryHolder = "INSERT INTO "+SQLiteHelper.TABLE_NAME+" (ProjectName,ProjectDescription,projType,projectStatus) VALUES('"+projectName+"', '"+projectDescription+"', '"+projType+"', '"+projStatus+"');";
sqLiteDatabase.execSQL(SQLiteDataBaseQueryHolder);
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
} else {
Toast.makeText(context, httpServiceClass.getErrorMessage(), Toast.LENGTH_SHORT).show();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
这是工作没有任何问题。但是,我想通过在我的
select
查询中添加where
条件来过滤特定用户的项目信息。如何通过我的getProjects.php
传递应用程序用户登录信息。是否可以将其作为参数添加到getProjectsURL
?您可以像GET一样传递用户名:
// example : http://www.example.com/login.php?username="+username+"&password="+password
String getProjectsURL = "http://192.168.0.102/syncsqlite/getProjects.php?username="+username;
并使用
$\u GET
在查询中使用首先将用户ID作为URL参数发送到页面,如下所示
String UserId = user.ID; //This is a demo code
String getProjectsURL = "http://192.168.0.102/syncsqlite/getProjects.php?userId="+UserId;
...
$userID = (isset($_GET['userId']))? $_GET['userId'] : 0;
$sql = "SELECT * FROM projects where projectStatus = 1 AND user_id = '".$userID."'";
...
在PHP代码中,您可以获得如下所示的用户ID
String UserId = user.ID; //This is a demo code
String getProjectsURL = "http://192.168.0.102/syncsqlite/getProjects.php?userId="+UserId;
...
$userID = (isset($_GET['userId']))? $_GET['userId'] : 0;
$sql = "SELECT * FROM projects where projectStatus = 1 AND user_id = '".$userID."'";
...
您可以将用户ID作为
String getProjectsURL=”发送http://192.168.0.102/syncsqlite/getProjects.php?userId=1111";代码>,我现在已经给出了一个虚拟id。您可以使用php中的$\u get['userId']