Home > Backend Development > PHP Tutorial > Detailed explanation of the code for implementing the points system in the PHP forum

Detailed explanation of the code for implementing the points system in the PHP forum

coldplay.xixi
Release: 2023-04-09 11:26:01
forward
2833 people have browsed it

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;
Copy after login

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;
Copy after login

ps: Let’s take a look at the method of deleting pictures in thinkphp

Usage scenarios:

New avatar replaces the old one

Steps:

1. Read the URL address of the database avatar

2 . Get the valid fields of the URL address

3. File file path setting

4. Delete the image file

Thinkphp code is as follows:

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

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!

Related labels:
source:jb51.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template