How can I make in PHP dropdown menu which will have options from 0 to certain number which mysqlquery will retrieve?
I’ve tried while loop but it just retrieves one option with value of mysql. iex. in mysql table there is value six (6). So I want it to printed like this:
<select name="count">
<option value="">Count</option>
<option value="1">1</option>
<option value="2">2</option>
.
.
.
<option value="6">6</option>
</select>
So far its this:
$count = mysql_query('SELECT count FROM table') or die ('MySQL error! Error with query!');
print('<select name="count">');
print('<option="">Count</option>');
while($values = mysql_fetch_array($count))
{
print('<option value="');
print $values;
print('">');
print $values;
print('</option>');
}
print('</select>');
Retrieve the number from your database – let us say it is stored in
$maxnum– then run through all the values from1to$maxnum, using aforloop, echoing an<option>element in each loop iteration.