php代码:
<?php
// $username = array();
// $password = array();
$userandpass = array();
include "con_mysql.php";
$conn = con_mysql("localhost", "root", "", "supermarket");
$sql = "SELECT username, password FROM sup_user;";
$result = $conn->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代码:
<view wx:for="{{t}}" wx:key="key">{{item.username}}</view>
<view wx:for="{{t}}" wx:key="key">{{item.password}}</view>
后台返回的数据: