Donovan Posted January 10, 2008 Share Posted January 10, 2008 I was using a foreach($_POST['a'] as $key => $value) { to process a loop, but have another issue. I have more than two values I am trying to pass to another page to process and the $key => $value isn't enough. I actually have 4 values for each record. I was loading the _POST array like this. "<td><input type='text' name='IRAT_Grade[{$SOMS_KEY}]' size='3' maxlength='3'></td>" So each grade would have a corrosponding SOMS_KEY value. But I also have $Group_ID, and $UID for each record. Is it possible for me to do this? . "<td><input type='text' name='IRAT_Grade[{$SOMS_KEY}]' size='3' maxlength='3'></td>" . "</tr>" . "<input type='hidden' name='IRAT_Grade[{$Group_ID}]' value='$Group_ID'>\n" . "<input type='hidden' name='IRAT_Grade[{$UID}]' value='$UID'>\n"; Then on the processing page do something like while (list($SOMS_KEY, $IRAT, $Group_ID, $UID) = each($IRAT_Grade)) { $sql = "INSERT INTO ".$prefix."_tl_session_grades (Session_ID, UID, Group_ID, SOMS_KEY, IRAT_Grade, Academic_Year)". "VALUES ('$Session_ID', '$UID', '$Group_ID', '$SOMS_KEY', '$IRAT', '$Academic_Year')"; $result = $db->sql_query($sql); if (!$result) {echo("<p>Error performing query: " . mysql_error() . "</p>");} } I think I would have to _POST the values somewhere as well same as I did here: foreach($_POST['a'] as $key => $value) Link to comment https://forums.phpfreaks.com/topic/85360-while-lista-b-c-d-eache/ Share on other sites More sharing options...
Donovan Posted January 10, 2008 Author Share Posted January 10, 2008 Anybody want to take a stab at this? Link to comment https://forums.phpfreaks.com/topic/85360-while-lista-b-c-d-eache/#findComment-435690 Share on other sites More sharing options...
cooldude832 Posted January 10, 2008 Share Posted January 10, 2008 do a foreach in the foreach <?php $data = array(); foreach($_POST as $key=> $value){ if(is_array($value)){ $data[$key] = array(); foreach($value as $k=>$v){ $data[$key][$k] = $v; } } else{ $data[$key] = $value; } ?> Link to comment https://forums.phpfreaks.com/topic/85360-while-lista-b-c-d-eache/#findComment-435694 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.