2014-03-27 55 views
0

如何創建一個輸入框的數組,其名稱按迭代次序如name = name1,name2 .....就像我想訪問它們下頁使用PHP使用for循環創建多個輸入框並訪問它們將其值存儲在數據庫中

echo"<form action='addprogrammerdetails.php' action='post'>"; 
       echo"<table border='0' class='corner' width='600'>"; 
       echo"<tr>"; 
       echo"<td>"; 
       echo"&nbsp;"; 
       echo"</td>"; 
       echo"</tr>"; 
       echo"<tr>"; 
       echo"<td colspan='2' bgcolor='#E57614'>"; 
       echo"PROGRAMMER DETAILS"; 
       echo"</td>"; 
       echo"</tr>"; 

       session_start(); 
       $nprog=$_SESSION['nprog']; 
       for($i=1;$i<=$nprog;$i++) 
       { 
        echo"<tr>"; 
        echo"<td>"; 
        echo"<table>"; 
        echo"<tr>"; 
       echo"<td width='300'>"; 
       echo"Programmer Number:"; 
       echo"</td>"; 
       echo"<td>"; 

       echo"<input type='text' name='no[]' value='$i' disabled/>"; 
       echo"</td>"; 
       echo"</tr>"; 
echo"</table>"; 

       echo"</td>"; 

       echo"</tr>"; 

       } 
       echo"<tr>"; 
       echo"<td colspan='2' align='center'>"; 
       echo"<input type='submit' value='SUBMIT'/>"; 
       echo"</td>"; 
       echo"</tr>"; 
       echo"</table>"; 
       echo"</form>"; 
       ?> 

回答

1

如果用[]命名元素,您可以訪問它作爲一個數組在PHP

$no1 = $_POST['no'][0]; 
$no2 = $_POST['no'][1]; 
$no3 = $_POST['no'][2]; 

OR

foreach($_POST['no'] as $values) { 
    // do something with $value 
} 
相關問題