-1

目前我有一个下拉菜单循环(循环取决于我可以定义的每页结果,你可以看到我为什么要使用循环),我想把下拉菜单变成单选按钮。下面是我的代码。你能给我一些关于如何转换它的指示吗?

if (isset($_POST['formSubmit'])){
    $rating = $_POST['rating'];
    $accountID = $_POST['accountID']; 

    $query = mysql_query("UPDATE Spreadsheet SET rating='$rating' WHERE accountID='$accountID'");
}

while ($row = mysql_fetch_array($query)){

    ?>

<form name ="rating" method ="POST" action ="" > <?

echo "<input type = 'hidden' name = 'accountID' value = '" . $row['accountID'] . "' >";

?>
    <select name="rating">

        <? 

        $values = array('0 - No rating','1 - Very Bad','2 - Bad','3 - Average','4 - Above Average');

        for ($i =0; $i < count($values); $i++){
            echo "<option value = \"$i\""; 

            if ($row['rating'] == $i) {
                echo "selected=\"selected\"";
            }

            echo ">" . $values[$i] . "</option>";

        }

        ?>

        </select>
        <input type ="Submit" name ="formSubmit" value ="Submit" />
        </form>
4

1 回答 1

0
     $values = array('0 - No rating','1 - Very Bad','2 - Bad','3 - Average','4 - Above Average');   


    <form name ="rating" method ="POST" action ="" >
     <?
    echo "<input type = 'hidden' name = 'accountID' value = '" . $row['accountID'] . "' >";
     for($i =0; $i < count($values); $i++)
    {
    ?>
     <input type="radio" name="rbl" value="<?php echo $row['rating']; ?>" id="rbl_<?php echo $i; ?>" <? if($row['rating'] == $i) echo "checked='checked'"; ?>/>

<label for="rbl_<?php echo $i; ?>"><?php echo $value[$i]; ?></label>


     <? } ?>

            <input type ="Submit" name ="formSubmit" value ="Submit" />
            </form>
于 2012-12-11T20:23:06.103 回答