Php number array from max, min, step size mysql data

I want to create a form with data values in a dropdown list. The values in the dropdown list need to be generated on the fly from max, min and increment values contained in a mysql database.

Hopefully this makes sense, I really have no idea where to start :confused:
Thanks

Something like:

<select>
<?php
for ( $i=$min; $i <= $max; $i+=$step) {
  echo "<option value='$i'>$i</option>";
}
?>
</select>

I was sort of hoping to include it as part of the sql query?

Can you explain a little more about how to get the increment value? How is it stored in the MySQL table?
For the minimum and maximum value you would normally perform something like this:

SELECT MIN(x), MAX(x) FROM mytable GROUP BY x

and wrap that around PHP code, which is not provided here, because it is the next step.

So the Min, Max and increment are all stored in the mysql table as integers, what I need to do is to great the array of values that will populate for the dropdown list. ie if Max=6, Min=0, increment=2 then I need the query to produce 0, 2, 4, 6

There are countless examples of that on the internet, for example here:
PHP Select Data From MySQL
From the first example on that page you would change this part:

while($row = $result->fetch_assoc()) {
        echo "id: " . $row["id"]. " - Name: " . $row["firstname"]. " " . $row["lastname"]. "<br>";
    }

into something that looks more like what CarloM provided.

Just a quick note here - MySQL does not have features that would make creating such a query easy. It does not support recursive "with" subqueries (also called CTEs - Common Table Expressions). It does not support hierarchical queries. It does not provide pipelined functions or functions to generate a series of numbers.
Given all these limitations, your best bet for a database query would be to pre-populate a table of integers and use it to return the number series you want. And then again, there is the problem of how many rows the table should contain, if its load is static.

The hassle-free alternative is to fetch those three values (min, max, increment) in PHP and generate the numbers in there. I do not know PHP, but by looking at the "for" loops the others have posted here, it doesn't look that complicated.

---------- Post updated at 11:23 PM ---------- Previous update was at 10:52 PM ----------

Nevertheless, the approach mentioned above for the database query is posted here. Let's say you **know** beforehand that the min value will never be below 0 and the max value will never be above 10. Then you can populate an "iterator" table (called "numbers" in the example below) with values from 0 to 10.
The rest should be easy to comprehend:

mysql>
mysql> create table dropdown (max int, min int, incr int);
Query OK, 0 rows affected (0.01 sec)

mysql> insert into dropdown (max, min, incr) values (6, 0, 2);
Query OK, 1 row affected (0.01 sec)

mysql>
mysql> create table numbers (value int);
Query OK, 0 rows affected (0.01 sec)

mysql> insert into numbers (value)
    -> select  0 union all
    -> select  1 union all
    -> select  2 union all
    -> select  3 union all
    -> select  4 union all
    -> select  5 union all
    -> select  6 union all
    -> select  7 union all
    -> select  8 union all
    -> select  9 union all
    -> select 10;
Query OK, 11 rows affected (0.00 sec)
Records: 11  Duplicates: 0  Warnings: 0

mysql>
mysql> commit;
Query OK, 0 rows affected (0.00 sec)

mysql>
mysql>
mysql> select * from dropdown;
+------+------+------+
| max  | min  | incr |
+------+------+------+
|    6 |    0 |    2 |
+------+------+------+
1 row in set (0.00 sec)

mysql>
mysql> select * from numbers;
+-------+
| value |
+-------+
|     0 |
|     1 |
|     2 |
|     3 |
|     4 |
|     5 |
|     6 |
|     7 |
|     8 |
|     9 |
|    10 |
+-------+
11 rows in set (0.00 sec)

mysql>
mysql> -- Query to generate the series (0,2,4,6) given the values
mysql> -- min=0, max=6, incr=2
mysql>
mysql> select n.value
    ->   from numbers n, dropdown d
    ->  where n.value between d.min and d.max
    ->    and mod(n.value - d.min, d.incr) = 0;
+-------+
| value |
+-------+
|     0 |
|     2 |
|     4 |
|     6 |
+-------+
4 rows in set (0.00 sec)

mysql>
mysql>

The limitation of this method should be easy to see. If you update the max value in the dropdown table to 1000, then the final query will return incorrect result unless you load numbers at least till 1000 in the iterator table.