php代码:
query($sql);
if ($result->num_rows > 0)
{
while($row = $result->fetch_assoc()) // 将表中的数据都取出来
{
$u_p = array();
// echo "username: ".$row['username']." password: ".$row["password"];
$u_p['username'] = $row['username'];
$u_p['password'] = $row['password'];
$userandpass[] = $u_p;
}
}
// $userandpass['username'] = $username;
// $userandpass['password'] = $password;
echo json_encode($userandpass);
?>
js代码:
// index.js
// 获取应用实例
const app = getApp()
Page({
data: {
t:"hwllo"
},
onLoad: function(){
var that = this;
wx.request(
{
url:"http://127.0.0.1/SM/select_alluser.php",
headers:{
'content-type':'application/json'
},
method:'GET',
success:res=>{
that.setData({
t:res.data
})
}
}
);
}
})
wxml代码:
{{item.username}} {{item.password}}
后台返回的数据:



