phpexcel如何在查询中直接设置where值

ivqmmu1c  于 2021-06-19  发布在  Mysql
关注(0)|答案(1)|浏览(387)

我使用phpexcel从mysql db to excel文件中提取值,并执行以下查询:
导出.php

$query = $db->query("SELECT id, home, away, scorehome, scoreaway, best_bets, oddtwo, oddthree, partialht, over05ht, over05sh, over05, over15, over25, over35, over45, goal, risultato,esito, campionato FROM risultati ORDER BY best_bets");

它正在工作,但现在我想将where语句从html表单直接设置到export.php文件中。我试过这样做,但没用:
表单.html

<!DOCTYPE html>

<html>
<head>
    <title></title>
</head>
<body>

<form method="post" action="export.php">
   <br><br>

  Corsa:
  <select name="tournaments">
    <option value="Aut-A">Austria A</option>
    <option value="Aut-B">Austria B</option>
    <option value="Bel-A">Belgio A</option>
    <option value="Bel-B">Belgio B</option>
    <option value="CoR-A">Costa Rica</option>
    <option value="Cro-A">Croatia</option>
    <option value="CZE-A">Czech Republic</option>
    <option value="Den-A">Denmark A</option>
    <option value="Den-B">Denmark B</option>
    <option value="Egy-A">Egypt</option>
    <option value="Fra-A">France A</option>
    <option value="Fra-B">France B</option>
    <option value="Ger-A">Germany A</option>
    <option value="Ger-B">Germany B</option>
    <option value="Ger-C">Germany C</option>

  </select>
  <br><br>

<input type="submit" name="submit" value="Submit"> 
</form>

</body>
</html>

我在export.php文件中输入以下代码:

if(isset($_POST['submit'])){
    if  (isset($_POST["tournaments"])) { 
        $tournamentsss = $_POST["tournaments"];
    }
}

...

$query = $db->query("SELECT id, home, away, scorehome, scoreaway, best_bets, oddtwo, oddthree, partialht, over05ht, over05sh, over05, over15, over25, over35, over45, goal, risultato, esito, campionato FROM risultati WHERE campionato = '$tournamentsss' ORDER BY best_bets");

我真的不知道怎么修复这个代码。
谢谢!
编辑:我编辑了我的代码,它是这样工作的。谢谢

pcrecxhr

pcrecxhr1#

提交表格后;你可以像这样直接得到“锦标赛”的价值:

if(isset($_POST['submit'])){
    if  (isset($_POST["tournaments"])) { 
        $tournamentssss = $_POST["tournaments"];
    }
}

ps:您的输入不允许多选。
您的查询可以这样写:

query = $db->query("SELECT id, home, away, 
                      scorehome, scoreaway, best_bets, 
                      oddtwo, oddthree, partialht, 
                      over05ht, over05sh, over05, over15, 
                      over25, over35, over45, goal, 
                      risultato, esito, campionato 
                    FROM risultati 
                    WHERE campionato = '$tournamentsss' 
                    ORDER BY best_bets");

希望这能帮到你
现在它是正确的,以你的方式它不工作

相关问题