我正在使用PHPExcel通过以下查询将我的mysql数据库中的值提取到Excel文件中:
export.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文件。 我以这种方式尝试过,但是没有用:
form.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");
我真的不知道如何解决此代码。
谢谢!
编辑:我编辑了代码,它以这种方式工作。谢谢
答案 0 :(得分:1)
提交表格后;您可以像这样直接获得“比赛”的值:
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");
希望这可以为您提供帮助
现在是正确的,以您的方式,它不起作用