Home  >  Article  >  Backend Development  >  An in-depth analysis of how PHP implements five judges’ scoring

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

PHPz
PHPzOriginal
2023-03-31 09:10:241077browse

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");

?>

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

?>

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 "<tr><td>".$i."</td><td>".$name."</td><td>".$average."</td></tr>";
    $i++;
}</p>
<p>?></p>
<p>3. Create a web interface</p>
<p>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: </p>
<p><!DOCTYPE html><br><html lang="en"><br><head></p>
<pre class="brush:php;toolbar:false"><meta charset="UTF-8">
<title>五位评委打分系统</title>


<form action="mark.php?id=<?php echo $_GET[&#39;id&#39;]; ?>" method="post">
    <label for="mark1">第一位评委打分:</label>
    <input type="number" name="mark1" id="mark1" required="required" step="0.1"><br>
    <label for="mark2">第二位评委打分:</label>
    <input type="number" name="mark2" id="mark2" required="required" step="0.1"><br>
    <label for="mark3">第三位评委打分:</label>
    <input type="number" name="mark3" id="mark3" required="required" step="0.1"><br>
    <label for="mark4">第四位评委打分:</label>
    <input type="number" name="mark4" id="mark4" required="required" step="0.1"><br>
    <label for="mark5">第五位评委打分:</label>
    <input type="number" name="mark5" id="mark5" required="required" step="0.1"><br>
    <input type="submit" value="提交评分">
    <input type="reset" value="重置评分">
</form>


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!

Statement:
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