【发布时间】:2018-12-13 08:25:57
【问题描述】:
所以我有一个包含 2 个表的数据库,一个用于用户活动,名为 tblactivity,另一个名为 tblusers:
tblactivity 包含一个用户的多个数据,我想根据我从tblusers 获取数据的登录用户在回收站视图中显示tblactivity 中的条目。 tblactivity 有 userid 专栏,我想知道如何去做。
编辑:更多详情:
所以我正在使用 slim 框架:DbConnect.php
//Method to get emails of a particular user
public function getActivity(){
$stmt = $this->con->prepare("SELECT id, userid, subject, message FROM tblactivity");
$stmt->execute();
$stmt->bind_result($id, $userid, $subject, $message);
$users = array();
while($stmt->fetch()){
$user = array();
$user['id'] = $id;
$user['userid'] = $userid;
$user['subject'] = $subject;
$user['message'] = $message;
array_push($users, $user);
}
return $users;
}
我的 index.php 代码
$app->get('/allactivity', function(Request $request, Response $response){
$db = new DbOperations;
$users = $db->getActivity();
$response_data = array();
$response_data['error'] = false;
$response_data['users'] = $users;
$response->write(json_encode($response_data));
return $response
->withHeader('Content-type', 'application/json')
->withStatus(200);
});
现在在安卓工作室:
我的 Activity.java 模型:
public class Activity {
private int id;
private int userid;
private String subject;
private String message;
private String to;
public Activity(String subject, String message) {
this.id = id;
this.userid = userid;
this.subject = subject;
this.message = message;
this.to = to;
}
public int getId() {
return id;
}
public int getUserid() { return userid; }
public String getSubject() { return subject; }
public String getMessage() {
return message;
}
public String getTo() { return to; }
}
User.java 模型
public class User {
private int id;
private String email;
private String firstname;
private String lastname;
private String companyname;
private String postcode;
private String city;
private String state;
private String phonenumber;
private String address1;
private String country;
private String status;
private int currency;
private String credit;
private String language;
private int email_verified;
public User(int id, String email, String firstname, String lastname, String companyname, String address1, String city,
String state, String postcode, String country, String phonenumber, String status, int currency, String credit,
String language, int email_verified) {
this.id = id;
this.email = email;
this.firstname = firstname;
this.lastname = lastname;
this.companyname = companyname;
this.address1 = address1;
this.city = city;
this.state = state;
this.postcode = postcode;
this.country = country;
this.phonenumber = phonenumber;
this.status = status;
this.currency = currency;
this.credit = credit;
this.language = language;
this.email_verified = email_verified;
}
public int getId() {
return id;
}
public String getEmail() {
return email;
}
public String getFirstName() {
return firstname;
}
public String getLastName() {
return lastname;
}
public String getCompanyName() { return companyname; }
public String getAddress1() {
return address1;
}
public String getCity() {
return city;
}
public String getState() { return state; }
public String getPostcode() {
return postcode;
}
public String getCountry() {
return country;
}
public String getPhonenumber() {
return phonenumber;
}
public String getStatus() { return status; }
public int getCurrency() { return currency; }
public String getCredit() {
return credit;
}
public String getLanguage() {
return language;
}
public int getEmail_verified() { return email_verified; }
}
我正在使用 Retrofit 客户端从 php 获取 json 输出。
@GET("allactivity")
Call<List<Activity>> getActivityData();
}
【问题讨论】:
-
到目前为止你有什么尝试?
-
请我在回复此线程的答案中提供我的详细信息和我的代码。请看一下,让我知道您是否可以提供帮助。非常感谢