Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End Grabbing data from multiple field pairs

  • This topic is empty.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #169347
    Josh Johnson
    Participant

    So I have 6 field pairs within a form:

    http://i.imgur.com/c6Dgm1d.png

    Which in code is just the following repeated 6 times respectively:

                         <fieldset>
                                <input type="text" name="skill-1" value="" class="field-1-2 float-left" placeholder="Skill"> 
                                <div class="select-container field-1-2 float-right">
                                    <select name="skill-rating-1">
                                        <option value="">Skill rating</option>
                                        <option value="1">1 (Beginner)</option>
                                        <option value="2">2 (Amateur)</option>
                                        <option value="3">3 (Intermediate)</option>
                                        <option value="4">4 (Pro)</option>
                                        <option value="5">5 (Expert)</option>
                                    </select>
                                </div>
                            </fieldset>      
    

    What I would like to know is how I would go about grabbing that data whilst maintaining field pairs are kept together (i.e skill one goes with skill rating one etc). Once I have that data I can then insert it as a row in the following database structure:

    +--------------+-------------+------+-----+---------+-------+
    | Field        | Type        | Null | Key | Default | Extra |
    +--------------+-------------+------+-----+---------+-------+
    | skill_id     | int(11)     | NO   | PRI | NULL    |       |
    | skill        | varchar(50) | NO   | PRI | NULL    |       |
    | skill_rating | int(11)     | YES  |     | NULL    |       |
    +--------------+-------------+------+-----+---------+-------+

    Thanks

    #169364
    shaneisme
    Participant

    Yes, each of the pairs would need a unique name you could parse to know they go together.

    For instance skill_1 goes with skill_rating_1. You could build this dynamically of course just using an increment (eg. $i++) in your foreach loop when rendering the form to the user.

    Then you could just parse looking for the _1 and pair them together.

    I’m sure there are other ways too, just what I thought up off the top of my head :)

Viewing 2 posts - 1 through 2 (of 2 total)
  • The forum ‘Back End’ is closed to new topics and replies.