php - 在flutter中使用php mysql根据用户登录显示数据
问题描述
我想显示表用户的用户配置文件数据。这是我的 PHP 代码:
<?php
include ("connect.php");
//$username = $_POST['username'];
$response = array();
$sql = mysqli_query($con,"SELECT agentName, agentCode, agentId FROM users WHERE username ='$username'");
while ($a = mysqli_fetch_array($sql)){
$b['agentName'] = $a['agentName'];
$b['agentCode'] = $a['agentCode'];
$b['agentId'] = $a['agentId'];
array_push($response, $b);
}
echo json_encode($response);
?>
但它不显示,但是当我用特定的用户名更改用户名时,数据会显示。我的代码有问题吗?
数据将显示在
_lihatUser() async {
list.clear();
setState(() {
loading=true;
});
final response = await http.get(BaseUrl.userData);
if (response.contentLength==2){
}else{
final data = jsonDecode(response.body);
data.forEach((api){
final ab = new userModel(
api['agentCode'],
api['agentId'],
api['agentName']
);
list.add(ab);
});
setState(() {
loading=false;
});
}
}
解决方案
推荐阅读
- javascript - 根据条件重新排列javascript数组
- android - MaterialCardView 包括所有孩子到位图
- java - 将对象添加到 ArrayList
- sql - 使用 TypeORM 在 Postgres 中回滚数据库更改
- java - 以 HTML 格式下载 Zip 文件
- angular - ionic 4/5 使用 ngx-translate 自动添加到 i18n 中的字幕文件
- python - 将数据附加到熊猫数据框
- altair - altair 无法使用 vconcat 分面图
- android - 无法手动激活 CALL_PHONE 权限(如果用户选择“不再显示此内容”)
- android - android gridlayout行和列与结果不匹配