您好,登录后才能下订单哦!
密码登录
登录注册
点击 登录注册 即表示同意《亿速云用户服务条款》
小编给大家分享一下微信小程序如何实现使用table显示数据库反馈的多条数据功能,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!
具体如下:
解决了微信小程序自定义表格,并显示的多条数据的问题。
index.wxml
<view>
<text>我的调查问卷</text>
<scroll-view scroll-x="true" >
<view class="table">
<view class="tr bg-header">
<view class="th">姓名</view>
<view class="th">性别</view>
<view class="th">年龄</view>
</view>
<view class="tr bg-items" wx:for = "{{items}}" wx:key="">
<text class="td">{{item.name}}</text>
<text class="td">{{item.gender}}</text>
<text class="td">{{item.age}}</text>
</view>
</view>
</scroll-view>
<button bindtap="change">查看我的数据</button>
</view>index.js
Page({
/**
* 页面的初始数据
*/
data: {
items:[]//定义变长数组
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
change:function(e){
var that=this;
wx.request({
url: 'https://../data.php',//自己的服务器地址
header: {
"Content-Type": "application/json"
},
method: "POST",
success: function (res) {
for (var i = 0, len = res.data.length; i < len; i++){
that.data.items[i] = res.data[i];
}
that.setData({
items: that.data.items
})
},
fail: function (res) {
wx.showToast({
'title': 'request fail'
})
}
})
}
})data.php
<?php $servername = "localhost"; $username = "root"; $password = "***";//数据库连接密码 $dbname = "mydb"; // 创建连接 $conn = new mysqli($servername, $username, $password, $dbname); // 检测连接 if ($conn->connect_error) { die("connect server fail: " . $conn->connect_error); } $query = "select * from table"; $result = mysqli_query($conn,$query); $data = array(); while ($rows = mysqli_fetch_assoc($result)) { $data[] = $rows; } echo json_encode($data); $conn->close(); ?>
以上是“微信小程序如何实现使用table显示数据库反馈的多条数据功能”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注亿速云行业资讯频道!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。