Home  >  Article  >  Backend Development  >  Detailed explanation of the ideas for implementing the PHP forum system

Detailed explanation of the ideas for implementing the PHP forum system

coldplay.xixi
coldplay.xixiforward
2020-08-12 16:54:512818browse

Detailed explanation of the ideas for implementing the PHP forum system

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 (video)

##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 how thinkphp deletes images to achieve

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;
}

Related recommendations:

Programming video course

The above is the detailed content of Detailed explanation of the ideas for implementing the PHP forum system. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:jb51.net. If there is any infringement, please contact admin@php.cn delete