php商城评论功能,PHP实现小程序留言板功能(完结)添加了评论功能

PHP实现小程序留言板功能(完结)

接着上面的文章添加了评论功能,先看看效果图把,如下图所示

c9cd520aff830ac8808fcf3e61d0e5a8.png

我这里没有做删除评论了,因为跟上篇文章的一样,就没有去做了,好了接下来就是评论功能代码

logs.wxml

留言内容:

提交留言

用户名:{{item.uname}}

内容:{{item.content}}

修改

删除

评论

确认

评论名称:{{cell.uname}}

评论内容:{{cell.text}}

logs.js

Page({

data: {

hidden: true

},

/**

* 生命周期函数--监听页面加载---获取从其他页面传来的值经行接收

*/

onl oad: function(options) {

this.setData({

id:options.id,

uid: options.uid,

uname: options.uname

})

var that = this

that.setData({

uids:that.data.uid

})

//查询留言

wx.request({

url: 'http://127.0.0.1/liuyanban.php',

data:{

'a':1

},

header: { 'content-type': 'application/json'},

method: 'GET',

dataType: 'json',

success: function(res) {

that.setData({

liuyantext: res.data['0'],

})

console.log('查询值', res.data['0'])

},

})

//查询评论

wx.request({

url:"http://127.0.0.1/huifu.php",

header:{'content-type':'application/json'},

data:{'a':1},

method:'get',

dataType:'json',

success:function(res){

that.setData({

huifutext: res.data['0'],

})

console.log("评论值",res.data['0'])

}

})

},

//插入留言

liuyanban: function(e) {

if(e.detail.value.content != ""){

var that = this

wx.request({

url: 'http://127.0.0.1/liuyanban.php',

data: {

"uid":this.data.uid,

"uname":this.data.uname,

"content":e.detail.value.content

},

header: { 'content-type': 'application/x-www-form-urlencoded'},

method: 'POST',

dataType: 'json',

success: function(res) {

console.log('插入数据值:',res)

},

})

}

console.log('留言内容',e.detail.value.content)

console.log('uid:', this.data.uid)

console.log('uname:', this.data.uname)

},

//删除

deletei: function (e) {

wx.showModal({

title: '提示',

content: '是否确定删除',

success(res) {

if (res.confirm) {

wx.request({

url: 'http://127.0.0.1/update.php',

method:"get",

header: { 'content-type': 'application/json'},

dataType:'json',

data:{

'a':2,

'id': e.currentTarget.dataset.src

},

success:function(){

wx.showToast({

title: '删除成功',

icon: 'none',

})

}

})

console.log('用户点击删除')

} else if (res.cancel) {

console.log('用户点击取消')

}

}

})

},

//评论功能

huifu:function(e){

console.log("点击了:",e.currentTarget.dataset.huifu)

this.setData({

arr: e.currentTarget.dataset.huifu

})

},

huifus:function(e){

wx.request({

url: 'http://127.0.0.1/huifu.php',

method:"post",

header:{ 'content-type': 'application/x-www-form-urlencoded'},

data:{

'blog_id': this.data.arr,

'uid': this.data.uid,

'uname': this.data.uname,

'text': e.detail.value.text

},

dataType:'json',

success:function(res){

wx.showToast({

title: '评论成功',

icon: 'none',

})

}

})

}

})

这些事没有封装,想封装的可以去看我钱面封装的文章,接下来就是评论的PHP了

huifu.php

class huifu{

//查询评论

public function select(){

require_once 'config.inc.php';

$sql = "select * from wt_huifu";

try{

$stmt = $link->prepare($sql);

$stmt->execute();

while($row = $stmt->fetch(PDO::FETCH_ASSOC)){

//要转成json格式给小程序才可以

$results[] = $row;

}

echo json_encode([$results]);

}catch(PDOException $e){

die($e->getMessage());

}

}

//插入评论

public function insert(){

require_once 'config.inc.php';

$sql = "insert into wt_huifu(blog_id,uid,uname,text) values(?,?,?,?)";

try{

$stmt = $link->prepare($sql);

$stmt->execute([$_POST['blog_id'],$_POST['uid'],$_POST['uname'],$_POST['text']]);

}catch(PDOException $e){

die($e->getMessage());

}

}

}

$a = new huifu();

if($_GET['a'] == 1){

$a->select();

}else{

$a->insert();

}

?>

还有一个评论功能的sql语句

create table wt_huifu(

id int PRIMARY KEY AUTO_INCREMENT,

blog_id int not null,

uid int not null,

uname varchar(22) not null,

text varchar(60) not null

)

最好是能一步一步来实现功能,要理解里面的原理,再给你们发一个源码吧,里面没有SQL,自己看前面文章,粘贴复制就好了,有什么问题欢迎评论留言,我会及时回复你的。

源码链接: https://pan.baidu.com/s/1wa0uZD5EmprH-rZd2jIhDQ 提取码: qc1f

标签:function,功能,uid,res,content,uname,PHP,data,留言板

来源: https://blog.csdn.net/qq_43764578/article/details/100082211

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值