我有一個表單使用php提交多個值。代碼如下:使用foreach循環將數據以數組的形式保存到mysql數據庫
echo "<form action='?ud=".$ud."' method='post'>Name: <input type='text' name='fname' />";
$resultw = mysql_query("SELECT * FROM options where userid='$ud' ORDER BY priority ASC");
while($row = mysql_fetch_array($resultw))
{
echo "
<input type='hidden' name='widgetid[]' value='".$row['widgetid']."' />
<span id='".$row['widgetid']."' style='color:white;font-size:13px;'>".$row['items'] . "</span><br></div><div style='' class='portlet_content'>
Enabled <input title='Enabled/Disabled' type='checkbox' value='enable[]' name='enable[]' ".$checked." id='checkbox".$row['id']."' />
Height <input title='set height' name='height[]' value='".$row['height']."' type='text' name='textfield' id='textfield".$row['id']."' />
";
}
echo '<input type="submit" /></form>';?>
正如你可以看到它的一個循環,它從數據庫中獲取值並回顯一個表單。我儘可能簡化它有更多的輸入框,但我刪除了它們並刪除了樣式以使其更易於閱讀。當我點擊提交時,我希望能夠通過循環將所有這些值更新到數據庫。 我嘗試過foreach並掙扎。任何建議
感謝您的幫助,這不是我實際的代碼,我刪除了一堆東西,使它更簡單對不起,我離開閉幕div標籤沒有開幕one.the價值被張貼我echo'd他們的作品。它是$高度[$ i]還是$高度[++ $ i]? – cppit 2012-03-03 13:25:28
只是$高度[$我]。您只需要每行增加$ i一次 - 所以我只是在第一次讀取時預先增加。 – christophmccann 2012-03-03 13:31:39