我有一個簡單的HTML表單。在PHP頁面上。一個簡單的列表放在窗體上。我將此表單(選定列表項目)提交到此頁面,以便讓頁面刷新。我希望在表單被提交後選擇POSTED的項目。如何在發佈後請求選擇表單項?
對於我的形式我用這樣的代碼,它工作得很好,但它是最佳的,或者你可以建議我的代碼一些優化?
<form action="FormPage.php" method="post">
<select id="Streams" class="multiselect ui-widget-content ui-corner-all" multiple="multiple" name="Streams[]">
<?php
$query = "
SELECT s.streamId, s.userId, u.username
FROM streams AS s
JOIN user AS u ON s.userId = u.id
LIMIT 0 , 30
";
$streams_set = mysql_query($query, $connection);
confirm_query($streams_set);
$streams_count = mysql_num_rows($streams_set);
while ($row = mysql_fetch_array($streams_set)){
if (isset($_POST['submitForm'])){
$array = $_POST[Streams];
$count = count($array);
echo ",sid=" ;
for ($i = 0; $i < $count; $i++) {
if($array[$i] == $row['streamId']){ echo '<option value="' , $row['streamId'] , '" selected="selected" > ' , $row['username'] , ' (' , $row['streamId'] ,')' ,'</option> '; }else
{ echo '<option value="' , $row['streamId'] , '"> ' , $row['username'] , ' (' , $row['streamId'] ,')' ,'</option> '; }
}
} else { echo '<option value="' , $row['streamId'] , '"> ' , $row['username'] , ' (' , $row['streamId'] ,')' ,'</option> ';}
}
</select>
<br/>
<input type="submit" class="ui-state-default ui-corner-all" name="submitForm" id="submitForm" value="Play Stream from selected URL's!"/>
</fieldset>
</form>
它工作,但只保存1所選項目...( – Rella 2010-04-05 11:53:01
對不起,我沒有看到,它是多項選擇固定 – vooD 2010-04-05 12:31:28