Page 1 of 1

Set amount of dropdown options, via DB - how?

Posted: Tue May 31, 2011 5:09 am
by simonmlewis
I want to have a dropdown <option> of between 1 and 100.

In a database, there will be the number set .... such as "35".

Then I want there to be:

Code: Select all

<select name='list'>
<option value='1'>1<option>
...
<option value='35'>35<option>
Or if it is 50, then it goes only to '50'.

How do I do that? Is it best with a "FOR"? I'm a bit weak when it comes to FOR LOOPS. Any help would be appreciated.

Re: Set amount of dropdown options, via DB - how?

Posted: Tue May 31, 2011 8:20 am
by Celauran
for loop would be the way I'd go about it. Assuming you've stored the value from the DB in $count, then

Code: Select all

for ($i = 1; $i <= $count; $i++)
{
    echo "<option value=\"{$i}\">{$i}</option>";
}