I have a simple html form. On php page. A simple list is placed on form. I submit this form (selected list items) to this page so it gives me page refresh. I want items which were POSTED to be selected after form was submited.
For my form I use such code, And It works just fine, But is it optimal or you can suggest some optimization for my code?
<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>