我有一个 PHP 页面,用于更新 MySQL 数据库中的分数。当前该页面显示来自数据库的值。我想将其更改为下拉列表(0-9),然后更新数据库。我是新手,无法弄清楚这一点。我们将非常感谢您的帮助。这是我到目前为止所拥有的。我已经截断了代码;
<h1>UPDATE SCORES</h1>
<form method="post" action="add_scores.php" >
<table width="60%" cellpadding="15" style="font-family: verdana, arial; border: #FFCC99 1px solid">
<tr>
<td height="28" colspan="24" align="center" style="font-size: 44px">
<strong><li>1st Quarter:</li></strong><br>
<strong><font color="#DB2824">NFC: </font></strong><input size="4" maxlength="1" name="away_first" value="<?php echo $record['away_first'];?>"/>
<strong><font color="#232B85">AFC: </font></strong><input size="1" maxlength="1" name="home_first" value="<?php echo $record['home_first'];?>"/>
<br><br>
最佳答案
没有测试它,但这个函数应该为您生成代码:
<?php
function generateSelect($name, $value) {
$str = "<select name='$name'>";
foreach(\range(0,9) as $i) {
$selected = $i == $value ? 'selected' : '';
$str .= "<option value='$i' $selected>$i</option>";
}
$str .= "</select>";
return $str;
}
关于带下拉菜单的 PHP 页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28376659/