【发布时间】:2010-04-05 11:08:39
【问题描述】:
我有一个简单的 html 表单。在 php 页面上。一个简单的列表放置在表单上。我将此表单(选定的列表项)提交到此页面,以便我刷新页面。我希望在提交表单后选择已发布的项目。
对于我的表单,我使用了这样的代码,它工作得很好,但它是最优的还是你可以建议对我的代码进行一些优化?
<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>
【问题讨论】:
标签: php html list forms select