【问题标题】:How to add multiple score results PHP MYSQL如何添加多个分数结果 PHP MYSQL
【发布时间】:2014-04-14 05:23:57
【问题描述】:

我想添加多个分数,但如果我这样做,第二次填写表格将无法正常工作。第一次填写表格运行良好。我知道这不是一个很好的代码,我怎么能用一种代码类型做到这一点?

希望你能帮忙。

这是我的代码:

<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']."') ");

                    }

                    ?>

【问题讨论】:

    标签: php html mysql scoring


    【解决方案1】:

    你的逻辑很奇怪,你的意思是:

    $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}
    

    我不确定你想要达到什么目标,但我会考虑修改

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-19
      • 2012-09-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多