gpt4 book ai didi

php - 查询是否正确,除了第 9 行之外的所有行

转载 作者:行者123 更新时间:2023-11-30 00:08:56 24 4
gpt4 key购买 nike

这是代码。每当我输入数据时它都工作正常。它正确地计算了除了游戏 #9 之外的每一行。除第 9 场比赛外,每场比赛均正确计数。我坐下来向三个人寻求帮助。现在我请你帮我找出为什么会发生这种情况。

这是代码:

<?php

include ("../conn_inc.php");
include ("../conn_inc_pdo.php");
require_once ('auth.php');

$game_id= $_POST['game_id'];
$resultat= $_POST['namn'];
$lag1=substr($resultat, 0,1);
$lag2=substr($resultat, 2,1);


if ($lag1>$lag2){
$tips="1";
}
if ($lag1<$lag2){
$tips="2";
}
if ($lag1==$lag2){
$tips="x";
}

//echo $tips;

//------------------FIND ALL ALREADY POSTED GAMES---------------\\

$sql2 = $pdo->prepare("SELECT game_id FROM vm2014res WHERE :game_id = game_id");
$sql2->execute(array(':game_id' => $game_id));

if ($sql2->rowCount() == 0) {

//------ IRRELEVANT TEST CODE 3 LINES DOWN-----\\
echo $game_id;
echo $resultat;
echo "<br>";


//----------- INSERT THE VALUE OF THE GAME IF IT DOESNT EXIST -------\\
$q = "INSERT INTO vm2014res (game_id, resultat, added) VALUES (:game_id, :resultat, CURRENT_TIMESTAMP)";
$query = $pdo->prepare($q);
$query->execute(array(
':game_id' => $game_id,
':resultat' => $resultat
));

//------------------CHECK IF YOU SHOULD BE GETTING POINTS FOR A CORRECT GUESSED RESULT---------------\\
$SQL = $pdo->prepare("SELECT * FROM vm2014 WHERE game_id = :game_id AND resultat = :resultat");
$SQL->execute(array(':game_id' => $game_id, ':resultat' => $resultat));
$r = $SQL->fetchAll(PDO::FETCH_ASSOC);
foreach($r as $row){


$bet_id = $row['bet_id'];
$game_id = $row['game_id'];
$tips = $row['tips'];
$resultat = $row['resultat'];
$namn = $row['namn'];
$points = $row['points'];

//-------- ALL ECHOS DOWN HERE ARE IRRELEVANT----------\\
echo $bet_id;
echo $game_id;
echo $tips;
echo $resultat;
echo $namn;
echo $points;
echo "<br>";
$points=$points+2;
echo $points;

//------------- UPDATE THE POINTS GOTTEN (2 POINTS)---------\\

$sql2 = $pdo->prepare("UPDATE vm2014 SET points = :points WHERE bet_id = :bet_id");
$sql2->execute(array(':points' => $points,
':bet_id' => $bet_id
));

}

//------------------CHECK IF YOU SHOULD BE GETTING POINTS FOR RIGHT GUESSED GAME---------------\\
$SQL = $pdo->prepare("SELECT * FROM vm2014 WHERE game_id = :game_id AND tips = :tips");
$SQL->execute(array(':game_id' => $game_id, ':tips' => $tips));
$r = $SQL->fetchAll(PDO::FETCH_ASSOC);
foreach($r as $row){


$bet_id = $row['bet_id'];
$game_id = $row['game_id'];
$tips = $row['tips'];
$resultat = $row['resultat'];
$namn = $row['namn'];
$points = $row['points'];

//-------IRRELEVANT ECHOS DOWN HERE--------\\
echo $bet_id;
echo $game_id;
echo $tips;
echo $resultat;
echo $namn;
echo $points;
echo "<br>";
$points=$points+1;
echo $points;

//----------------- UPDATE YOUR POINTS IF YOU SHOULD BE GETTING POINTS FOR THE GAME----\\

$sql2 = $pdo->prepare("UPDATE vm2014 SET points = :points WHERE bet_id = :bet_id");
$sql2->execute(array(':points' => $points,
':bet_id' => $bet_id
));

}

} else {
//-----------------POST WHEN THE GAME RESULT WAS ADDED TO THE DB-------\\
$SQL6 = $pdo->prepare("SELECT * FROM vm2014res WHERE game_id = :game_id");
$SQL6->execute(array(':game_id' => $game_id));
$ra = $SQL6->fetchAll(PDO::FETCH_ASSOC);
foreach($ra as $row){

$game_id = $row['game_id'];
$resultat = $row['resultat'];
$added = $row['added'];

echo "Resultatet är redan registrerat. Det registrerades: <strong>" . $added . "</strong> och det vart <strong>" . $resultat . "</strong> i matchen.";
}
}

我包含了整个代码部分,因为我不知道代码的错误部分在哪里。它应该位于后面的部分:

//------------------Kolla om du ska få poäng för ditt tips---------------\\

但我看不出问题所在。

我在游戏 9 中输入 2-1。这是数据库的输入:(我不知道如何在这个网站上制作一个表格)

    bet_id  game_id tips    resultat    name      poäng     9           9   1       2-1         Player 1  2     57          9   x       1-1         Player 2  0     105         9   x       1-1         Player 3  0     153         9   1       2-0         Player 4  0     201         9   1       2-1         Player 5  2     249         9   1       3-0         Player 6  0     297         9   x       1-1         Player 7  0     345         9   x       0-0         Player 8  0     393         9   2       0-1         Player 9  1     441         9   1       1-0         Player 10 0     489         9   2       0-3         Player 11 1     537         9   x       0-0         Player 12 0     585         9   x       1-1         Player 13 0     633         9   1       2-0         Player 14 0     681         9   2       1-2         Player 15 1     729         9   2       0-1         Player 16 1     777         9   x       1-1         Player 17 0     825         9   1       3-0         Player 18 0     873         9   2       2-3         Player 19 1     921         9   2       0-1         Player 20 1     969         9   x       2-2         Player 21 0     1017        9   x       2-2         Player 22 0     1065        9   2       2-1         Player 23 3     1113        9   x       0-0         Player 24 0     1161        9   2       1-1         Player 25 1 

正如您所看到的,一些玩家因犯错而获得积分。有些人会因为正确的结果而获得积分,但不会因为猜测谁赢得了比赛而获得积分。

有人可以帮我找出问题所在吗?

最佳答案

首先计算$tips:

if ($lag1>$lag2){
$tips="1";
}

然后,用数据库结果覆盖它:

//------------------CHECK IF YOU SHOULD BE GETTING POINTS FOR A CORRECT GUESSED RESULT---------------\\
/* ... */
$tips = $row['tips'];

其中一个变量应具有不同的名称。

一些进一步的问题:

$resultat= $_POST['namn'];

我假设 $resultat 是游戏的结果,'namn' 是玩家的名字。这不可能是正确的。

$lag1=substr($resultat, 0,1);
$lag2=substr($resultat, 2,1);

如果一支球队在一场比赛中进球超过 9 个怎么办?你应该explode'-'作为分隔符的结果。

关于php - 查询是否正确,除了第 9 行之外的所有行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24247999/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com