我正在用PHP创建一个网站,为我的学校记录乒乓球分数,目前获胜的玩家将登录WinnerID, LoserID, PointsFor, PointsAgainst.我有两个表有以下关系.
表:用户
表:游戏
我在php文件中的insert语句是:
INSERT INTO games(WinnerID,LoserID,PointsFor,PointsAgainst) VALUES('$Winner_ID','$Loser_ID','$userscore','$oppscore')"
Run Code Online (Sandbox Code Playgroud)
这是我尝试过的,但它没有正确显示分数.
SELECT min(u.username) 'Username', COUNT(g.WinnerID) 'Wins', sum(g.PointsFor) 'Points For', sum(g.PointsAgainst) 'Points Against', u.Elo 'Ranking'
from games g
LEFT JOIN users u
on g.WinnerID = u.user_id
Group by g.WinnerID
Run Code Online (Sandbox Code Playgroud)
正如您在上图中所看到的,总计的点数和点数不会相加.目前,它仅显示获胜者的统计数据.意味着如果PlayerA赢得21-5,它将从select语句中显示,但是PlayerB将不会显示5-21的分数.任何帮助表示赞赏.
用于输入分数的页面的PHP代码:
if(isset($_POST['btn-post']))
{
$opponent = $_POST["opponent"];
//$opponent = array_key_exists('opponent', $_POST) ? $_POST['opponent'] : false;
$userscore = mysql_real_escape_string($_POST['userscore']);
$oppscore = mysql_real_escape_string($_POST['oppscore']);
if($userscore != $oppscore)
{
if($userscore > $oppscore)
{
$Winner_ID = …Run Code Online (Sandbox Code Playgroud)