This forum is no longer open and is for reading/searching only.

Please use our new MachForm Community Forum instead.

MachForm Community Forums » MachForm 2

[closed] drop downs and MySQL


  1. Molina
    Member

    Hi Yuniar,

    I bought your software one week ago and I like it a lot, it's easy to use and the forms look very well! Now I'd like to read the data to show them on a webpage and I got a problem that has to do with the drop downs and multiple choices. How can I output them?
    5 months ago, grg had a similar problem (forum topic: Mysql Question) and you answered, that one has to join the 2 tables, ap_form_XX and ap_element_options. This is basically clear; in your sample you wrote:

    select
    A.*,B.option
    from
    ap_form_99 A left join ap_element_options B
    on
    A.element_2=B.option_id and B.element_id=2
    where
    B.form_id=99

    but what is "select A.*, B.option"?
    Let's say I got some elements_1 to elements_5 as textfields, numbers or whatever, which are working very well, and element_6, element_7 in ap_form_XX as drop downs and option_id and option in ap_element_options - but no A and B, for sure ;-)
    I'm not very experienced in MySQL, so at the moment I don't have a clue, please give me hint! What do I have to write in the lines SELECT and FROM?

    Much thanks in advance
    Molina

    Posted 16 years ago #
  2. yuniar

    Hi Molina,

    Actually, those A and B are just alias for those tables.
    In your case, the query would be more complex, since you have two dropdowns.

    Ok, let say you have table ap_form_271
    element_1 to element_5 are textfields and element_6 and element_7 are dropdowns.

    Your query would be like this:

    select
          A.*,
          B.option as element_6_value,
          C.option as element_7_value
      from
          (ap_form_271 as A
           left join ap_element_options as B
                  on A.element_6=B.option_id and B.element_id=6 and B.form_id = 271)
           left join ap_element_options as C
                  on A.element_7=C.option_id and C.element_id=7 and C.form_id=271


    So it uses two joins. One to get the value of your first dropdown and second for the other one. A, B and C are just table alias, so you can use it as is.
    You only need to change the 271 values.


    MachForm Founder

    Posted 16 years ago #
  3. yuniar

    This forum can't display backtick properly. So if the above query give you an error, try to copy this one: http://mf.pastebin.com/f7fcdbcc2


    MachForm Founder

    Posted 16 years ago #
  4. Molina
    Member

    Yuniar, you're great!
    Thanks a lot, it works fine and I learned a little bit more :-)
    Maybe I will have to ask another question...

    Molina

    Posted 16 years ago #
  5. expat
    Member

    i thought in another post the admin says you can populate a drop down list???

    So with this you can actually generate a php form that connects to the Mysql??

    Posted 16 years ago #
  6. yuniar

    You will be able to create forms which connect to your mysql database. all submission will be stored on your database.


    MachForm Founder

    Posted 16 years ago #
  7. Molina
    Member

    Hi,

    Yuniar, how can I extract the values for checkboxes via MySQL in a query? Would you please help me again?
    Thanks
    Molina

    Posted 16 years ago #
  8. yuniar

    Molina, the query would be exactly the same as dropdowns.
    Checkboxes and dropdowns are treated similar.

    Post your query here if you can't seem to make it work.
    I'll try to help.


    MachForm Founder

    Posted 16 years ago #
  9. Molina
    Member

    Hi,

    I've got 2 checkboxes, for example (I hope it's understandable):
    checkbox 1 = element_id 2, option_id 1, option = "first V"
    checkbox 2 = element_id 2, option_id 2, option = "second V"
    The query

    SELECT
    A.*,
    B.option AS element_2_1_value,
    C.option AS element_2_2_value
    FROM
    (ap_form_28 AS A
    LEFT JOIN ap_element_options AS B
    ON A.element_2_1=B.option_id AND B.element_id=2 AND B.form_id=28)
    LEFT JOIN ap_element_options AS C
    ON A.element_2_2=C.option_id AND C.element_id=2 AND C.form_id=28

    is working correctly for the first element.
    But the second choice alway returns the value of the first one; it inserts "1" into the database as you can see in the source code of the html-page:
    <input id="element_2_2" name="element_2_2" class="element checkbox" type="checkbox" value="1" />.
    If I want to output the value "second V" written in ap_element_options of the second checkbox too I have to change the datatabase in ap_form_28 from "1" to "2", then the output is what I'd like to get: "second V".
    Is there something wrong?
    Or is there normally only a Yes- or No-option?
    Thanks again for help!
    Molina

    Posted 16 years ago #
  10. yuniar

    Oops..you are right. I forgot that checkboxes only have Yes (1) or No (0) values.

    A little adjustment is needed to your query. Try this:

    SELECT
    A.*,
    B.option AS element_2_1_value,
    C.option AS element_2_2_value
    FROM
    (ap_form_28 AS A
    LEFT JOIN ap_element_options AS B
    ON A.element_2_1=1 AND B.element_id=2 AND B.option_id=1 and B.form_id=28)
    LEFT JOIN ap_element_options AS C
    ON A.element_2_2=1 AND C.element_id=2 AND C.option_id=2 and C.form_id=28


    MachForm Founder

    Posted 16 years ago #
  11. Molina
    Member

    :-) Great!
    Thanks, how easy things can be...

    Posted 16 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.