簡體   English   中英

將值添加到表單的單選按鈕,然后使用PHP選擇[輸入類型]

[英]Add value to form's radio button and select[input type] using PHP

好的,我有一個選擇框(下拉菜單)和一組單選按鈕。

選擇您的班級:

<form action="" method="post">
<select name="class">
<option value="a">A</option>
<option value="b">B</option>
</select>
<br><br>

Red or blue:<br>
<input type="radio" name="red" value="red">Red
<input type="radio" name="blue" value="blue">Blue
</form>

我已將PHP腳本連接到數據庫,並從表中檢索了數據,並將其存儲在變量中以進行回顯。 ROW是Mysql提取數組。

$class = $row['class']
$color = $row['color']

我如何在單選按鈕和選擇框中顯示它(通常對於文本框,我將值設置為<? php echo $foo ?>

有人能幫我嗎?

//read the data from database 

$row=mysql_fetch_row($result);
//assuming that the first data cell fetched is for dropdown list and the second is for radio button thats why $row[0] and $row[1] is used
<form action="" method="post">
<select name="class">
<option value="a" <?php if($row[0]=='a'){?> selected <?php } ?> >A</option>
<option value="b" <?php if($row[0]=='b'){?> selected <?php } ?> >B</option>
</select>
<br><br>

Red or blue:<br>
<input type="radio" name="red" value="red" <?php if($row[1]=='red'){?> checked<?php } ?>>Red
<input type="radio" name="blue" value="blue" <?php if($row[1]=='blue'){?> checked<?php } ?>>Blue
</form>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM