当前位置:网站首页>微信小程序之获取php后台数据库转化的json
微信小程序之获取php后台数据库转化的json
2022-06-23 13:12:00 【qq_45911550】
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>
后台返回的数据:

边栏推荐
- 何小鹏:如果可以回到创业的时候 不会以自己的名字给产品命名
- OpenVINOTM 2022.1中AUTO插件和自动批处理的最佳实践
- What are the conditions for a mature knowledge management?
- OS的常见用法(图片示例)
- 实战监听Eureka client的缓存更新
- .Net怎么使用日志框架NLog
- 2022 年以后,对AI开发人员意味着什么
- Interrupt and polling
- 从类、API、框架三个层面学习如何设计可复用软件的学习心得
- Hanyuan high tech USB2.0 optical transceiver USB2.0 optical fiber extender USB2.0 optical fiber transmitter USB2.0 interface to optical fiber
猜你喜欢

Has aaig really awakened its AI personality after reading the global June issue (Part 1)? Which segment of NLP has the most social value? Get new ideas and inspiration ~

前AMD芯片架构师吐槽,取消 K12 处理器项目是因为 AMD 怂了!

Quartus call & Design d Trigger - simulation & time sequence Wave Verification

怎么手写vite插件

2 万字 + 30 张图 |MySQL 日志:undo log、redo log、binlog 有什么用?
[email protected] Hdmi2.0 optical transceiver HDMI HD video optical transceiver"/>4k-hdmi optical transceiver 1 channel [email protected] Hdmi2.0 optical transceiver HDMI HD video optical transceiver
kubernetes日志监控系统架构详解

Modelsim 安装步骤详解
Detailed explanation of kubernetes log monitoring system architecture

Broadcast level E1 to aes-ebu audio codec E1 to stereo audio XLR codec
随机推荐
MIT 6.031 Reading5 : Version Control学习心得
怎么手写vite插件
90%的人都不懂的泛型,泛型的缺陷和应用场景
OS的常见用法(图片示例)
DBMS in Oracle_ output. put_ How to use line
Use openvinotm preprocessing API to further improve the reasoning performance of yolov5
windows 安装 MySQL
64 channel telephone +2-channel Gigabit Ethernet 64 channel PCM telephone optical transceiver voice telephone to optical fiber
What is the principle of live CDN in the process of building the source code of live streaming apps with goods?
What are the conditions for a mature knowledge management?
[Yunzhou said live room] - digital security special session will be officially launched tomorrow afternoon
Stick to five things to get you out of your confusion!
Esp32-c3 introductory tutorial problem ⑦ - fatal error: ESP_ Bt.h: no such file or directory ESP not found_ bt.h
What is the version of version 1.54 when connecting to Oracle?
快速了解常用的非对称加密算法,再也不用担心面试官的刨根问底
Androd Gradle模块依赖替换如何使用
kubernetes日志监控系统架构详解
Online text entity extraction capability helps applications analyze massive text data
Loss, duplication and backlog of message queues
通过 OpenVINO Model Server和 TensorFlow Serving简化部署