【发布时间】:2015-04-27 19:47:08
【问题描述】:
我有一个通过 phpmyadmin 设置并通过 PHP 连接的 MYSQL 数据库。我接下来要做的是当我从下拉框中选择一个播放器时,我希望它在我的字段列中的值(当我运行我的程序时实际上并没有显示)从 1 更改为 0,这样播放器就不会显示再次启动,直到我再次运行我的程序。
另外,我如何能够在我已经显示的所有未选择球员的表格旁边的单独表格中显示已经选择的球员?
<!DOCTYPE html>
<html>
<!-- Seth Rataiczak -->
<head>
<title>PHP Project</title>
<style>
table,th,td {
border: 1px solid navy;
}
</style>
</head>
<body>
<?php
$db_hostname='localhost';
$db_username='root';
$db_password='';
$db_database='Project';
$connection = new mysqli( $db_hostname,
$db_username,
$db_password,
$db_database);
$sql = "SELECT * FROM NFL_2014_Receiving WHERE Field=1";
$result = $connection->query($sql);
if (!$result) die ($connection->error);
$n = $result->num_rows;
$nfl = array();
echo "<table>
<tr><th>ID</th><th>Player</th><th>Team</th>
<th>Position</th><th>Receptions</th>
<th>Receiving Yards</th><th>Avg Yds/Catch</th>
<th>Avg Yds/Game</th><th>Touchdowns</th></tr>";
for ($i=1; $i<=$n; $i++) {
$row = $result->fetch_array(MYSQLI_ASSOC);
$nfl[$row['iD']] = $row['Player'];
if(!isset($_POST['hide']) || $_POST['hide'] != $row['iD']){
echo "<tr><td width=20>" . $row['iD'] . "</td><td width=150>" . $row['Player'] . "</td><td width=40>" .
$row['Team'] . "</td><td width=30>" . $row['Pos'] . "</td><td width=30>" .
$row['Rec'] . "</td><td width=40>" . $row['Yds'] . "</td><td width=30>" .
$row['Avg'] . "</td><td width=40>" . $row['Yds/G'] . "</td><td width=20>" .
$row['TD'] . "</td></tr>";
}
}
echo "</table><br>";
echo "<form method='post' action=''><select name='hide'>";
foreach($nfl as $key=>$value){
echo "<option value='".$key."'>".$value."</option>";
}
echo "<input type='submit' value='Submit'>";
echo "</select></form>";
?>
</body>
</html>
【问题讨论】:
-
我无法理解您的问题,但您正在选择框内打印您的输入提交。
-
您打算在选择播放器时 ping 数据库或执行页面刷新?最简单的做法是在该表上放置一个只返回活跃玩家的视图。但是,这对于简单的查询毫无意义。
-
好的,所以目前我正在显示一个数据库,其中包含 NFL 接收器列表及其 2014 年的统计数据。每当我从下拉框中选择一个名称时,该名称就会被隐藏。但是,如果我选择另一个玩家,最初选择的玩家将被放回表中。因此,我创建了一个名为 Field 的列(未显示但仍然存在)。 Everyones value is set to 1 in this field, but when selected i want there value to be 0 so they will not be displayed anymore until i run the program again.这有意义吗?
-
你可以在 click 方法上使用 jquery hide()Show() 函数。
标签: php mysql database phpmyadmin