gpt4 book ai didi

php - MySQL/PHP编码程序

转载 作者:行者123 更新时间:2023-11-30 22:45:29 25 4
gpt4 key购买 nike

我有以下代码将我的 phpmyadmin 数据库链接到我的 PHP 脚本。该代码采用了一张包含 50 名 NFL 球员及其上赛季统计数据的表格。现在,我希望能够对其进行编码,以便我可以通过下拉框或类似的某种下拉框/列表选择一个播放器,然后在选择并再次显示表格时,不会列出该播放器。但是,我被卡住了,不知道该怎么做。至少有人可以帮助我了解基础知识以及为此我需要什么吗?

<!DOCTYPE html>
<html>
<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);

if ($connection->connect_error) {
echo "Sorry";
} else {
echo "Connected!<br><br>";
$sql = "SELECT * FROM NFL2014Receiving";
$result = $connection->query($sql);
if (!$result) die ($connection->error);
$n = $result->num_rows;

for ($i=1; $i<=$n; $i++) {
$row = $result->fetch_array(MYSQLI_ASSOC);

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>";

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>";
}

?>

</body>
</html>

最佳答案

你可以这样做:

<?php
$db_hostname='localhost';
$db_username='root';
$db_password='';
$db_database='Project';

$connection = new mysqli( $db_hostname,
$db_username,
$db_password,
$db_database);

if ($connection->connect_error) {
echo "Sorry";
} else {
echo "Connected!<br><br>";
$sql = "SELECT * FROM NFL2014Receiving";
$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>";
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>";
}

?>

试试吧,如果它对你有用,请告诉我:-)

关于php - MySQL/PHP编码程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29736595/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com