Submit lessons

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
xionhack
Forum Contributor
Posts: 100
Joined: Mon Nov 10, 2008 9:22 pm

Submit lessons

Post by xionhack »

Hello. I have a huge confusion on how to do this. I have two tables

Members:
member_id, first_name, last_name

Studies:
study_id, study_name, member_id, times_studied, understanding

Then I have a table in html, where I ask to fill choose from many studies, if the person did that study, how many times have that person studied, and if that person understood. My problem is that I dont know how to do the function in order for it to save the values in the correct way. Im going to show some code to show an example.

Code: Select all

<form action="whatever.php" method="post">
<table>
<tr>
<td>Study Name</td>
<td>Studied?</td>
<td>Times Studied</td>
<td>Understanding</td>
</tr>

<tr>
<td>Study 1</td>
<td><input type="checkbox" name="?" value="?" /></td>
<td><select name="?">
       <option name="?" value="?">1</option>
       <option name="?" value="?">2</option>
       <option name="?" value="?">3</option>
       <option name="?" value="?">4</option>
      </select></td>
<td><select name="?">
       <option name="?" value="?">Understood</option>
       <option name="?" value="?">Didnt Understand</option>
       <option name="?" value="?">Needs Review</option>
      </select></td>
</tr>

<tr>
<td>Study 2</td>
<td><input type="checkbox" name="?" value="?" /></td>
<td><select name="?">
       <option name="?" value="?">1</option>
       <option name="?" value="?">2</option>
       <option name="?" value="?">3</option>
       <option name="?" value="?">4</option>
      </select></td>
<td><select name="?">
       <option name="?" value="?">Understood</option>
       <option name="?" value="?">Didnt Understand</option>
       <option name="?" value="?">Needs Review</option>
      </select></td>
</tr>

<tr>
<td>Study 3</td>
<td><input type="checkbox" name="?" value="?" /></td>
<td><select name="?">
       <option name="?" value="?">1</option>
       <option name="?" value="?">2</option>
       <option name="?" value="?">3</option>
       <option name="?" value="?">4</option>
      </select></td>
<td><select name="?">
       <option name="?" value="?">Understood</option>
       <option name="?" value="?">Didnt Understand</option>
       <option name="?" value="?">Needs Review</option>
      </select></td>
</tr>




etc....

</table>
</form>

When I have to submit this form, I already have the member_id that will be stored with these values. If it was only 1 line I could do it easily, but because there are so many, i really dont know how to do it. If somebody can, please help me!!
User avatar
mecha_godzilla
Forum Contributor
Posts: 375
Joined: Wed Apr 14, 2010 4:45 pm
Location: UK

Re: Submit lessons

Post by mecha_godzilla »

Are these values going to be edited by the member again at some point? Are the number of study options going to change?

What you might want to do is include a new column in your 'studies' table that records whether that study option has been taken or not, then you just INSERT a row for each study option per member (IE you'd have 7 rows per user if you had 7 study options) and if the studied option isn't selected then you just insert NULL into the other values in the row.

Ideally, what you might want to do is take all your $_POST values and recompile them into a new array, then you could just loop through your MySQL INSERT query as many times as necessary. I probably have some code somewhere that would do this - in my forms, what I sometimes do is set a unique id for each <select> element using an incremented counter (such as id="option_' . $counter . '") then in my script I'd search for any $_POST values that contain "option_" in their name and use string operators to retrieve the number, then this would be used as one of my keys in the array. This might be over-complicating what you need of course :)

Is this what you're trying to do, or have I misunderstood you?

HTH,

Mecha Godzilla
Post Reply