微信小程序如何用table展示数据库返回的长尾词数据列表?

2026-04-09 15:501阅读0评论SEO基础
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计592个文字,预计阅读时间需要3分钟。

微信小程序如何用table展示数据库返回的长尾词数据列表?

原文:本文字例讲述了微信小程序实现用table显示数据库反馈的多条数据功能。分享给大 家供参考,具体如下:解决了微信小程序自定义表格格式的难题,并展示了的多条数据的问题。

改写后:本例展示了微信小程序如何使用table展示数据库的多条数据反馈。分享此经验供大家参考,具体内容如下:成功解决了微信小程序自定义表格格式的难题,并展示了如何处理多条数据的问题。

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

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

微信小程序如何用table展示数据库返回的长尾词数据列表?

index.wxml

<view> <text>我的调查问卷</text> <scroll-view scroll-x="true" style=" white-space: nowrap; display: flex"> <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: '../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(); ?>

文章有借鉴,并非全部自创

希望本文所述对大家微信小程序开发有所帮助。

本文共计592个文字,预计阅读时间需要3分钟。

微信小程序如何用table展示数据库返回的长尾词数据列表?

原文:本文字例讲述了微信小程序实现用table显示数据库反馈的多条数据功能。分享给大 家供参考,具体如下:解决了微信小程序自定义表格格式的难题,并展示了的多条数据的问题。

改写后:本例展示了微信小程序如何使用table展示数据库的多条数据反馈。分享此经验供大家参考,具体内容如下:成功解决了微信小程序自定义表格格式的难题,并展示了如何处理多条数据的问题。

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

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

微信小程序如何用table展示数据库返回的长尾词数据列表?

index.wxml

<view> <text>我的调查问卷</text> <scroll-view scroll-x="true" style=" white-space: nowrap; display: flex"> <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: '../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(); ?>

文章有借鉴,并非全部自创

希望本文所述对大家微信小程序开发有所帮助。