微信小程序实现用table显示数据库反馈的多条数据功能示例

2022-01-11,,,,

这篇文章主要介绍了微信小程序实现用table显示数据库反馈多条数据功能,涉及微信小程序wx.request访问php后台及返回结果的显示布局相关操作技巧,需要的朋友可以参考下

本文实例讲述了微信小程序实现用table显示数据库反馈的多条数据功能。分享给大家供大家参考,具体如下:

解决了微信小程序自定义表格,并显示的多条数据的问题。

index.wxml

  我的调查问卷   姓名性别年龄 {{item.name}}{{item.gender}}{{item.age}}

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

 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显示数据库反馈的多条数据功能示例的详细内容,更多请关注本站其它相关文章!

《微信小程序实现用table显示数据库反馈的多条数据功能示例.doc》

下载本文的Word格式文档,以方便收藏与打印。