MySQL implementation of an iterator
is it a way to implement an iterator in mysql which could return a column as "1/10" "2/10" ... "10/10"
Lets say the form is a/b, as input we have only b. Is it possible to solve this without procedure?
EDIT An example. We have a relation PRINTS (id, work_id, edition_no) and EDITIONS (id, work_id, size, edition_size). For web-interface I am trying to render a select with possible options for prints. Html-options should look like
<option value="1">1/10</option>
<option value="2">2/10</option>
All my select list I render with SQL from database, but in this case I do not see any possibility to get it from database in way I need it. Sql should return 2 columns with option-value and option-text. That i开发者_运维百科s a question.
SQL is all about relations, that is, tables. The natural way would be to create a one-column table with 10 (or however much you want) consecutive numbers, index it by that column, and select
enough numbers from there, using order by
and limit
.
Use the CONCAT function to concatenate strings in MySQL:
SELECT CONCAT('<option value="', p.edition_no, '">', p.edition_no. '/', e.edition_size, '</option>')
FROM PRINTS p
JOIN EDITIONS e ON e.work_id = p.work_id
精彩评论