这就是我从 php 中查看结果的方式。
<块引用>final String uri =
'My PHP FILE';
Future<List<Dbjobs>> dbgetdbusers() async {
var response = await http.get(uri);
if (response.statusCode == 200) {
final items = json.decode(response.body).cast<Map<String, dynamic>>();
List<Dbjobs> dbusers = items.map<Dbjobs>((json) {
return Dbjobs.fromJson(json);
}).toList();
print(dbusers);
return dbusers;
} else {
throw Exception('Failed to load data.');
}
}
@override
Widget build(BuildContext context) {
return FutureBuilder<List<Dbjobs>>(
future: dbgetdbusers(),
builder: (context, snapshot) {
if (!snapshot.hasData)
return Center(child: CircularProgressIndicator());
return ListView(
children: snapshot.data
.map((data) => Column(
children: <Widget>[
GestureDetector(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => JobDetails()));
},
child: Column(
children: <Widget>[
Container(
color: Colors.grey,
child: Column(
children: <Widget>[
Align(
alignment: Alignment.topLeft,
child: Text(
data.dateCreated,
style: TextStyle(fontSize: 30.0),
),
),
我的登录php
<块引用><?php
session_start();
include 'testConz.php';
$username = $_POST['Username'];
$password =md5($_POST['Password']);
$Consult = $connect -> query("SELECT * FROM tuser_ppim WHERE LoginName = '$username' and Password = '$password' ");
$Result = array();
while ($extractData=$Consult->fetch_assoc()) {
$Result[] = $extractData;
}
$ID = $Result['0']['ID'];
$_SESSION['$Consult'] = $Result;
echo json_encode($Result);
?>
>
这个php文件与flutter一起工作,有基于查询的结果。
<?php
session_start();
include 'testConz.php';
$Consult1=$connect->query("
SELECT * FROM tjob WHERE AssignedTo = '6';
");
$Outcome1 = array();
while ($extractData=$Consult1->fetch_assoc()) {
$Outcome1[] = $extractData;
}
echo json_encode($Outcome1);
?>
>
这个让我的屏幕加载没有结果。有什么想法吗?
<?php
session_start();
include 'testConz.php';
$userDetails = $_SESSION['$Consult'];
$SesID = $userDetails['0']['ID'];
$Consult1=$connect->query("
SELECT * FROM tjob WHERE AssignedTo = ".$SesID.";
");
$Outcome1 = array();
while ($extractData=$Consult1->fetch_assoc()) {
$Outcome1[] = $extractData;
}
echo json_encode($Outcome1);
echo json_encode($userDetails);
?>
>
顺便说一句,AssignedTo 的数字都等于 6 和 两者在浏览器中都会产生相同的结果。但是当它在颤动屏幕中时,另一个没有结果。 谢谢!