我在从单选按钮表单中提取数据时遇到问题。
它看起来像这样:
<?php
## color
$stripe = 1;
$att_color=mysql_query("SELECT * FROM product_attributes WHERE products_id ='".$row['products_id']."' AND att_head='colors' AND att_show='1' ORDER BY att_order asc");
if(mysql_num_rows($att_color)!=0)
{
echo "
<table>
<tr>
<td width=\"90%\" align=\"left\" bgcolor=\"#EDEDED\">Color</td>
<td width=\"10%\" align=\"center\" bgcolor=\"#891531\">
<a href=\"#2\" title=\"Yta / Behandling\"><img src=\"images/info.png\"></a>
</td>
</tr>";
while($color_row=mysql_fetch_array($att_color)){
if ($color_row['att_standard'] == 1) { $standard = "checked"; }
echo "
<tr class=".(($stripe++%2==1) ? 'odd' : 'even').">
<td colspan=\"2\" width=\"100%\">
<input name=\"color_name[]\" value=\"".$color_row['att_name']."\" id=\"".$color_row['att_order']."\" type=\"hidden\" />
<input type=\"radio\" name=\"color_selected[]\" id=\"".$color_row['att_order']."\" value=\"".(round($color_row['att_val']*0.85))."\" ".$standard.">
<img src=\"images/colors/".$colorimg."\"> ".$color_row['att_name']."</td>
</tr>";
unset($standard); }
echo "</table>"; }
# END color
?>
只允许一个选项。当有人点击提交时,我*需要从该行获取值和相应的名称。但是我似乎无法弄清楚 foreach 语法。
if( isset($_POST['submit']) ) {
$c_selected = $_POST['color_selected'];
$c_name = $_POST['color_name'];
foreach($c_selected as $key => $n) {
echo "<br><br>". $c_selected[$key] ." ".$c_name[$key];
}
当前代码给了我正确的值,但颜色名称错误。(总是第一个选项)我怎样才能让它工作?