An in-depth analysis of how PHP implements five judges' scoring

PHPz
Release: 2023-04-11 14:20:02
Original
1021 people have browsed it

With the development of society, various selection activities have become more and more popular in recent years, and the scoring system is undoubtedly one of the most important components of the selection activities. In the scoring system, PHP language is widely used as a server-side scripting language.

So, how to achieve the five judges' scoring of PHP? The following will give you a detailed introduction.

1. Establish the database

First of all, the database must be established. In the SQL statement, we need to create the "score_table" table, which includes five fields: "sid", "mark1", "mark2", "mark3", "mark4", and "mark5".

2. Write PHP code

Next, we need to write PHP code to implement judges’ scoring, average score calculation and performance sorting respectively.

1. Judges’ scoring

The code for judges’ scoring is as follows:

//(1)连接数据库 $connect=mysqli_connect("localhost","root","密码","test"); //(2)防止中文乱码 mysqli_query($connect,"set names utf8"); //(3)获取id值 $sid=$_GET['id']; //(4)获取新数据 $mark1=$_POST['mark1']; $mark2=$_POST['mark2']; $mark3=$_POST['mark3']; $mark4=$_POST['mark4']; $mark5=$_POST['mark5']; //(5)更新数据 mysqli_query($connect,"update score_table set mark1=$mark1,mark2=$mark2,mark3=$mark3,mark4=$mark4,mark5=$mark5 where sid=$sid");
Copy after login

?>

2. Average score calculation

The code for average score calculation is as follows:

//(1)连接数据库 $connect=mysqli_connect("localhost","root","密码","test"); //(2)防止中文乱码 mysqli_query($connect,"set names utf8"); //(3)查询所有数据 $sql="select * from score_table"; $query=mysqli_query($connect,$sql); //(4)遍历数据 while($row=mysqli_fetch_array($query)){ $average=($row['mark1']+$row['mark2']+$row['mark3']+$row['mark4']+$row['mark5'])/5; $sid=$row['sid']; //(5)更新数据 mysqli_query($connect,"update score_table set average=$average where sid=$sid"); }
Copy after login

?>

3. Score sorting

The code for sorting results is as follows:

//(1)连接数据库 $connect=mysqli_connect("localhost","root","密码","test"); //(2)防止中文乱码 mysqli_query($connect,"set names utf8"); //(3)查询所有数据 $sql="select * from score_table order by average desc"; $query=mysqli_query($connect,$sql); //(4)遍历数据 $i=1; while($row=mysqli_fetch_array($query)){ $name=$row['name']; $average=$row['average']; echo "".$i."".$name."".$average.""; $i++; }

?>

3. Create a web interface

Finally, we need to create A web interface that allows users to rate players by entering their names. The code for the web interface is as follows:



 五位评委打分系统
Copy after login







Copy after login


4. Summary

Through the above steps, we can achieve PHP was scored by five judges. Of course, the above code is for reference only, you can also modify and improve it according to your own needs. In short, the implementation of the scoring system is a process of continuous optimization and updating. Only continuous learning and progress can provide better guarantee for the smooth holding of the selection activities.

The above is the detailed content of An in-depth analysis of how PHP implements five judges' scoring. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!