开发者

Poplate html drop down box

EDIT: THANKS - I MANAGED IT IN THE END

SHOULD HAVE TRIED FOR LONGER BEFORE POSTING

SORRY

how do you populate a drop down html box within a form, but populate it with values from a php array

for example

<form name="mname" action="index.php" method="post">
<select name='values'>
<option> </option>
<option> </option>
</form>

i can do it by echoing it out, thus not needing the form, but i really need to get at the value i am echoing in th开发者_如何学Goe drop down box later, so was hoping someone could show me how it can be done like this, using php


<?php
    foreach ($myArray as $value) {
        $checked = ($_GET['values'] == $value) ? " checked" : "";
        $saveValue = htmlspecialchars($value);
        print "<option$checked>$safeValue</option>";
    }
?>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜