2015-10-08 33 views
-3

我已經創建了一個包含4個元素的數組,並且我想要使用一個循環來顯示數組中的每個元素的4個單選按鈕。它的工作,但我可以在同一時間檢查我的所有單選按鈕如何解決此問題問題?爲什麼所有的單選按鈕都可以同時檢查?

我的代碼:

<!doctype html> 
<html> 
<head> 
<meta charset="utf-8"> 
<title>Untitled Document</title> 
</head> 

<body> 

<?php 


$Realisateurs=array(" James Cameron", " David O. Russell", " Woody Allen" , " Michael Haneke"); 

?> 

<?php 
for($i=0;$i<4;$i++) 
{ 
    ?> 
    <input type="radio" name"group1" value="<? $Realisateurs[$i] ?>"><?php echo $Realisateurs[$i] ?><br> 
    <?php 

} 
?> 

</body> 
</html> 

結果: result of my code

回答

0
<input type="radio" name"group1" value="<? $Realisateurs[$i] ?>"><?php echo $Realisateurs[$i] ?><br> 

替換爲:

<input type="radio" name="group1" value="<? $Realisateurs[$i] ?>"><?php echo $Realisateurs[$i] ?><br> // you missing the equal sign after name 

失蹤=標誌在name"group1"

0
Error Was there. 

- name"group1" should be name="group1" 
- value="" here, you are not echoing. Echo value here. Otherwise null will get printed. 

<!doctype html> 
    <html> 
    <head> 
     <meta charset="utf-8"> 
     <title>Untitled Document</title> 
    </head> 
    <body> 
     <?php 
     $Realisateurs=array(" James Cameron", " David O. Russell", " Woody Allen" , " Michael Haneke"); 
     for($i=0;$i<4;$i++) 
     {?> 
      <input type="radio" name="group1" value="<?echo $Realisateurs[$i];?>"><?php echo $Realisateurs[$i]; ?><br> 
     <?}?> 
    </body> 
    </html> 
相關問題