Mr Chris Posted September 23, 2008 Share Posted September 23, 2008 Hi all, Wondering if you could help me with something. I want to post two rows of data in one form, and it's working well: <?php if(isset($_POST['submit'])) { $user_id = $_GET["user_id"]; foreach($_REQUEST['r'] as $the_answer) { $result = mysql_query("Insert into cfm_survey (question_number,the_answer,user_id) values('$the_question','$the_answer','$user_id')"); } header("Location:survey.php?sec=3&user_id=1"); } //End of POST submit ?> <td style="width:100px;">Option 1</td> <INPUT TYPE="hidden" NAME="a[1]" VALUE="1" /> <td style="width:80px;"><INPUT TYPE="radio" name="r[1]" value="Yes"></td> <td style="width:80px;"><INPUT TYPE="radio" name="r[1]" value="No"></td> </tr> <tr> <td style="width:100px;">Option 2</td> <INPUT TYPE="hidden" NAME="a[2]" VALUE="1a" /> <td style="width:80px;"><INPUT TYPE="radio" name="r[2]" value="Yes"></td> <td style="width:80px;"><INPUT TYPE="radio" name="r[2]" value="No"></td> </tr> </tbody> </table> ...and you will see from the above code that the foreach code grabs the value for each of the $the_answer values and posts it accordingly. However, you will also see a hidden value called 1 and 1a which I also want to post to the database as well in a variable named $the_question, in row one (value 1), and then in the second row (value 1a). But I can't work out how to do it? I tried to add an && operator to the for each and go from there, but php did not like it. Any ideas? Thanks Chris Link to comment https://forums.phpfreaks.com/topic/125460-for-each-help/ Share on other sites More sharing options...
JasonLewis Posted September 23, 2008 Share Posted September 23, 2008 Use a for() loop instead. for($i = 1; $i <= count($_POST['r']); $i ++){ echo $_POST['r'][$i]."<br>"; echo $_POST['a'][$i]."<br><br>"; } Link to comment https://forums.phpfreaks.com/topic/125460-for-each-help/#findComment-648589 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.