php - PHP MYSQL 如何添加多个评分结果

标签 php html mysql scoring

我想添加多个分数,但如果我这样做,第二个填写的表格将不起作用。第一份填写的表格效果很好。我知道这不是一个好的代码,我怎样才能用一种代码类型来做到这一点?

希望能帮到你。

这是我的代码:

<form action="e2admin.php" method="post">
            <div class="input-group">
             <input style="width:410px;" type="text" class="form-control" name="date" placeholder="Datum" /><br>
                <select name="thuisteam1">
                    <option value=""></option>
                    <?php
                        mysql_data_seek($result, 0);

                        if(mysql_num_rows($result) > 0){
                            while($row = mysql_fetch_array($result)) {
                               echo '<option value="' . $row['Team'] . '">' . $row['Team'] . '</option>';
                            }
                        }
                     ?>

                </select>
                <input style="width:20px; text-align:center;" type="text" class="form-control" name="scorethuis1" placeholder="0" />
                -
                <input style="width:20px; text-align:center;" type="text" class="form-control" name="scoreuit1" placeholder="0" />
                <select name="uitteam1">
                    <option value=""></option>
                    <?php
                        mysql_data_seek($result, 0);

                        if(mysql_num_rows($result) > 0){
                            while($row = mysql_fetch_array($result)) {
                               echo '<option value="' . $row['Team'] . '">' . $row['Team'] . '</option>';
                            }
                        }
                     ?>
                </select><br>
                <select name="thuisteam2">
                    <option value=""></option>
                    <?php
                        mysql_data_seek($result, 0);

                        if(mysql_num_rows($result) > 0){
                            while($row = mysql_fetch_array($result)) {
                               echo '<option value="' . $row['Team'] . '">' . $row['Team'] . '</option>';
                            }
                        }
                     ?>

                </select>
                <input style="width:20px; text-align:center;" type="text" class="form-control" name="scorethuis2" placeholder="0" />
                -
                <input style="width:20px; text-align:center;" type="text" class="form-control" name="scorethuis2" placeholder="0" />
                <select name="uitteam2">
                    <option value=""></option>
                    <?php
                        mysql_data_seek($result, 0);

                        if(mysql_num_rows($result) > 0){
                            while($row = mysql_fetch_array($result)) {
                               echo '<option value="' . $row['Team'] . '">' . $row['Team'] . '</option>';
                            }
                        }
                     ?>
                </select><br>
                <input style="margin-left:330px;" type="submit" class="form-control" value="Toevoegen" />
                </div>
            </form>         
                    <?php

                    if( $_POST['scorethuis1'] > $_POST['scoreuit1']) {
                            //echo $_POST["thuisteam1"]; 
                            mysql_query("UPDATE e2teams SET Punten = Punten+3 WHERE Team ='".$_POST['thuisteam1']."'");

                    }
                    else if( $_POST['scorethuis1'] > $_POST['scoreuit1']) {
                            //echo $_POST["thuisteam1"]; 
                            mysql_query("UPDATE e2teams SET Punten = Punten+3 WHERE Team ='".$_POST['uitteam1']."'");

                    }
                    else if( $_POST['scorethuis1'] == $_POST['scoreuit1']) {
                            //echo $_POST["thuisteam1"]; 
                            mysql_query("UPDATE e2teams SET Punten = Punten+1 WHERE Team in ('".$_POST['thuisteam1']."', '".$_POST['uitteam1']."') ");

                    }

                    else if( $_POST['scorethuis2'] > $_POST['scoreuit2']) {
                            //echo $_POST["thuisteam1"]; 
                            mysql_query("UPDATE e2teams SET Punten = Punten+3 WHERE Team ='".$_POST['thuisteam2']."'");

                    }
                    else if( $_POST['scorethuis2'] > $_POST['scoreuit2']) {
                            //echo $_POST["thuisteam1"]; 
                            mysql_query("UPDATE e2teams SET Punten = Punten+3 WHERE Team ='".$_POST['uitteam2']."'");

                    }
                    else if( $_POST['scorethuis2'] == $_POST['scoreuit2']) {
                            //echo $_POST["thuisteam1"]; 
                            mysql_query("UPDATE e2teams SET Punten = Punten+1 WHERE Team in ('".$_POST['thuisteam2']."', '".$_POST['uitteam2']."') ");

                    }

                    ?>

最佳答案

这是你那里发生的一些奇怪的逻辑,你基本上说的是:

$foo = 1
if($foo > 1) {//you'll skip this}
else if($foo > 1) {//and this}
else if($foo == 1) {//and get here}

$foo = 2
if($foo > 1) {//you'll get here}
else if($foo > 1) {//skip this}
else if($foo == 1) {//and this}

我不确定您想要实现什么目标,但我会考虑修改

关于php - PHP MYSQL 如何添加多个评分结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22311496/

相关文章:

php - 我应该如何在给定结构中执行树遍历?

php - PHP 中如何处理并发请求(使用线程、线程池或子进程)

php - Laravel 迁移部署

javascript - 当我尝试在 onsubmit 函数中调用函数时,函数未定义

java - Pretty print ("indentation-only") Java 中的 HTML 文档(无 JTidy)

html - 雪碧表图像不显示

mysql - 在一个表中查找与不同表中的其他记录没有关联的记录

php - 在已经包含其他页面的页面中包含 .js 和 .css 的最有效方法是什么?

mysql - GROUP BY 子句未正确显示行

mysql - 获取两个表之间的匹配行,否则在左表中获取 NULL