如何从php创建select

I am trying to create some code to do a list of components in mysql.
Something like this

decod - 1,2,3,4,5

and to make it in drop-down listlike this

decod (dorplist) 1
2
3
4
5

I tried this one:

<?php
$mysqli = mysqli_connect("host", "username", "password", "name");

$result = mysqli_query($mysqli, 'SELECT * FROM componnets') or die(mysqli_error(mysqli));



while ($row = mysqli_fetch_array($result)) {
    $org = str_replace("," , "'>", $row['fill']."");
    $replace = str_replace("," , "
    ".$org."</option><option value='", $row['fill']."'>");

echo "<input type='hidden' name='compo' value='".$row['compon']."'>".$row['compon']."";
echo "<select name='fill'>";
echo "<option value='".$replace."'>".$replace."</option>";
echo "</select>";
}

// Free result set
mysqli_free_result($result);
/* close connection */
$mysqli->close();
?>

and do make it output to an XML

but I don't know how! I output like this

<input type='hidden' name='compo' value='DECODERS'>DECODERS
<select name='fill'>
<option value='1010'>20'>30'>40</option>
<option value='2010'>20'>30'>40</option>
<option value='3010'>20'>30'>40</option>
<option value='40'>'>1010'>20'>30'>40</option>
<option value='2010'>20'>30'>40</option>
<option value='3010'>20'>30'>40</option><option value='40'></option>
</select>
<input type='hidden' name='compo' value='DECODERS'>DECODERS
<select name='fill'>
<option value='10'>10</option>
</select>

First create the <select> outside the while loop. Then iterate over the rows to add the elements.

I'm not sure what you're trying to accomplish with your str_replace calls, so I removed them.

Something like this might get you started in the right direction:

<?php

$result = mysqli_query($mysqli, 'SELECT * FROM componnets') or die(mysqli_error(mysqli));

echo "<select name='fill'>";
echo "<input type='hidden' name='compo' value='".$row['compon']."'>".$row['compon']."";
while ($row = mysqli_fetch_array($result)) {    
echo "<option value='".$row['fill']."'>".$row['fill']."</option>";
}
echo "</select>";    
mysqli_free_result($result);
$mysqli->close();
?>