I need some help creating an array. I'm familiar with visual basic to do the task that i need, but i'm not sure how to do it with php.
I need a 'do while loop' to populate a forms 'select field' options so that i may populate a select with options from 1000 to 2000, instead of actually making a thousand select options.
Thanks 🙂
You don't necessarily need an array, if I understand the question. A for() loop should be sufficient:
<select name='foo'> <?php for($i = 1000; $i <= 2000; $i++) { echo "<option>$i</option>\n"; } ?> </select>
Or am I missing something?
NogDog;10956840 wrote:You don't necessarily need an array, if I understand the question. A for() loop should be sufficient: <select name='foo'> <?php for($i = 1000; $i <= 2000; $i++) { echo "<option>$i</option>\n"; } ?> </select> Or am I missing something?
nope that's it. works like a charm. pretty similar to vb, it was the syntax for the echoing of the html that i was having trouble with. thanks a lot 🙂
I prefer this because I use WYSIWIG
<?php $sql = "SELECT id, description FROM table"; $results = mysql_query($sql); while($x = mysql_fetch_assoc($results)) { $rows[] = $x; } ?> <select name='foo'> <?php foreach($rows as $row) { ?> <option value=<?php echo $row[id]; ?>><?php echo $row[description]; ?></option> <?php } ?> </select>