Home > Article > Backend Development > Detailed explanation of the code for implementing the points system in the PHP forum
First define a points field in the user table;
Then create a level table. The main fields include level name, upper limit points and lower limit points;
Then accumulate points based on the user's behavior;
Finally, determine the level range of the user's points to determine the user level.
Related learning recommendations: PHP programming from entry to proficiency
##User table
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;
Level table
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: Let’s take a look at the method of deleting pictures in thinkphp
Usage scenarios:
New avatar replaces the old oneSteps:
1. Read the URL address of the database avatar2 . Get the valid fields of the URL address3. File file path setting4. Delete the image fileThinkphp code is as follows:<?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; }
The above is the detailed content of Detailed explanation of the code for implementing the points system in the PHP forum. For more information, please follow other related articles on the PHP Chinese website!