meisenheimer Posted September 23, 2010 Share Posted September 23, 2010 In my form I have this: <div class="confSub {conferences.confClass}"> <div> <input type="hidden" name="confPK" value="{conferences.confPK}"> <label>Conference Attended:</label><input size="85" name="conference[{conferences.confCounter}]" type="text" value="{conferences.conference}"/> <label>Date:</label><input size="20" name="confDate[{conferences.confCounter}]" type="text" value="{conferences.confDate}"/> <span class="example left"> ( YYYY-MM-DD )</span> <label class="fullLabel clearfix">Description and Benefit to the University:</label> <textarea name="confDesc[{conferences.confCounter}]" cols="90" rows="5">{conferences.confDesc}</textarea> <input class="checkbox clearfix" name="confPres[{conferences.confCounter}]" value="yes" type="checkbox" {conferences.checkedConf}/> <label class="midLabel">Conference Presentation?</label> <label class="clearfix">Title of Presentation:</label> <input class="pushLeft" size="85" name="confPresTitle[{conferences.confCounter}]" type="text" value="{conferences.ConfPresTitle}"/> </div> </div> I need to take the values of the same index for eachof five arrays ($_POST['conference'], $_POST['confDate'], $_POST['confDesc'], etc...) and insert/update them into a mysql table. So conference[0], confDate[0], confDesc[0], confPres[0], and confPresTitle[0] all need to go into the same index of their respective fields in the DB table. If it was one array I could just do something like: foreach($_POST['conference'] as $conference) { // Update Conference $degreeQuery = "UPDATE CONFERENCES SET Conference = '".$conference."', StaffPK1 = '".$getPK1."' WHERE ConferencePK1 ='".$confID."'"; $degreeQuery = mysql_query($degreeQuery); } I'm having trouble with how to add a value from each array into the sql table. I could do it through a different foreach loop for each array and iterate through all foreach loops with another loop, but that doesn't seem very efficient. I'd like to do it with one sql statement for each set of "conference" data. Thanks in advance, Shannon Quote Link to comment Share on other sites More sharing options...
btherl Posted September 23, 2010 Share Posted September 23, 2010 Here is one option: foreach($_POST['conference'] as $index => $conference) { // Update Conference // Access $_POST['confDate'][$index], $_POST['confDesc'][$index], etc etc. You can use either $conference or $_POST['conference'][$index] $degreeQuery = "UPDATE CONFERENCES SET Conference = '".$conference."', StaffPK1 = '".$getPK1."' WHERE ConferencePK1 ='".$confID."'"; $degreeQuery = mysql_query($degreeQuery); } Quote Link to comment Share on other sites More sharing options...
meisenheimer Posted September 23, 2010 Author Share Posted September 23, 2010 Ah yes, key-value pairs. Beauty. I'll give it a try. Thanks, Shannon Quote Link to comment Share on other sites More sharing options...
meisenheimer Posted September 24, 2010 Author Share Posted September 24, 2010 Thanks btherl, Worked like a charm. Shannon Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.