溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

微信小程序如何實(shí)現(xiàn)使用table顯示數(shù)據(jù)庫反饋的多條數(shù)據(jù)功能

發(fā)布時(shí)間:2021-06-26 14:14:05 來源:億速云 閱讀:576 作者:小新 欄目:web開發(fā)

小編給大家分享一下微信小程序如何實(shí)現(xiàn)使用table顯示數(shù)據(jù)庫反饋的多條數(shù)據(jù)功能,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!

具體如下:

解決了微信小程序自定義表格,并顯示的多條數(shù)據(jù)的問題。

index.wxml

<view>
 <text>我的調(diào)查問卷</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">查看我的數(shù)據(jù)</button>
</view>

index.js

Page({
 /**
  * 頁面的初始數(shù)據(jù)
  */
 data: {
  items:[]//定義變長數(shù)組
 },
 /**
  * 生命周期函數(shù)--監(jiān)聽頁面加載
  */
 onLoad: function () {
 },
 /**
  * 生命周期函數(shù)--監(jiān)聽頁面顯示
  */
 onShow: function () {
 },
 /**
  * 生命周期函數(shù)--監(jiān)聽頁面隱藏
  */
 onHide: function () {
 },
 change:function(e){
  var that=this;
  wx.request({
   url: 'https://../data.php',//自己的服務(wù)器地址
   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 = "***";//數(shù)據(jù)庫連接密碼
$dbname = "mydb";
// 創(chuàng)建連接
$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();
?>

以上是“微信小程序如何實(shí)現(xiàn)使用table顯示數(shù)據(jù)庫反饋的多條數(shù)據(jù)功能”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對大家有所幫助,如果還想學(xué)習(xí)更多知識,歡迎關(guān)注億速云行業(yè)資訊頻道!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI