首先在用户表定义一个积分字段;

然后创建一个等级表,主要字段有等级名,上限积分和下限积分;

再根据用户的行为进行积分累加;

最后根据判断用户积分在哪个等级范围,从而得出用户等级。

用户表

create table `bbs`.`user`(
 `id` int(10) unsigned not null auto_increment comment '用户id',
 `avatar` varchar(255) not null comment '头像',
 `nickname` varchar(60) not null comment '昵称',
 `username` varchar(16) not null comment '用户名',
 `password` char(32) not null comment '密码',
 `points` int(10) not null default '0' comment '积分',
 primary key(`id`)
) engine = myisam;

等级表

create table `bbs`.`level`(
 `id` int(10) unsigned not null auto_increment comment '等级id',
 `name` varchar(60) not null comment '等级名',
 `max_points` int(10) unsigned not null comment '积分上限',
 `min_points` int(10) unsigned not null comment '积分下限',
 primary key(`id`)
) engine = myisam;

ps:下面看下thinkphp删除图片的方法实现

使用场景:

新头像替换旧的头像

步骤:

1. 读取数据库头像的url地址

2. 获取url地址的有效字段

3. file文件路径设置

4. 删除图片文件

thinkphp 代码如下:

<?php
public function delpic(){
  //获取用户id
  $uid = input('uid');
  if(!$uid){
    $this->error('uid未获取');
  }
  //获取url
  $img = m('member')->where('uid',$uid);
  $url = $img->avatar; //$url = 'http://www.test.com/up/avatar/59b25bcfcaac6.jpg'
  if(!$url){
    $this->error('获取头像失败');
  }
  //获取url有效字段(去掉网址)
  $str = parse_url($url)['path'].parse_url($url)['query'];//$str = '/up/avatar/59b25bcfcaac6.jpg'
  //file文件路径
  $filename = '.'.$str;
  //删除
  if(file_exists($filename)){    
    unlink($filename);
    $info = '原头像删除成功';
  }else{
    $info = '未找到原头像'.$filename;
  }
  echo $info;
}

总结

到此这篇关于php论坛实现积分系统的思路代码详解的文章就介绍到这了,更多相关php论坛积分系统内容请搜索www.887551.com以前的文章或继续浏览下面的相关文章希望大家以后多多支持www.887551.com!