As obtained from the database of strings to make the form select?

There is such code
$sql = $db->query("SELECT `str_code` FROM $db_str WHERE str_area='forma'");
while($item = $sql->fetch()){
$res = $item['str_code'];
}
need the received lines from the base to put for entering in the form as select
< form method="post"> //the form itself
< select name="polling"> //drop-down menu that clogged the array
//clogging the drop-down list
< /select>
< input type="submit" value="Ok" />
July 9th 19 at 10:34
3 answers
July 9th 19 at 10:36
Solution
< select name="polling"> //drop-down menu that clogged the array
<?php while($item = $sql--->fetch()):?>
<option><?=$item['str_code'];?></option>
<?php endwhile;?>
< /select>
Thank you. The problem here is it does not display the php code in the template, the value of the variable displays - christian commented on July 9th 19 at 10:39
use some templating engine? In any case, you need to first result record into an array and then in a loop to create list items - bryana.Renn commented on July 9th 19 at 10:42
In the cycle $res displays all the rows you need, that I can't find how these lines set the array directly in the loop or outside (does not work), then from the array I would have already decided. - christian commented on July 9th 19 at 10:45
$res[] = $item['str_code']; ? - bryana.Renn commented on July 9th 19 at 10:48
: Thank you ogromnoe, a small piece and I had spent a lot of time. - christian commented on July 9th 19 at 10:51
July 9th 19 at 10:38
php
echo in a loop.
and the res array must be
Thank you. And how to make res an array? - christian commented on July 9th 19 at 10:41
July 9th 19 at 10:40
Thank you all

Find more questions by tags MySQLArrays