vicodin Posted August 3, 2008 Share Posted August 3, 2008 Ok i need to update 5 things in mysql all at the same time. The table is in this format: ------------------------ ID | Event | Link | Date | ------------------------ 1 | x | x | x | 2 | x | x | x | 3 | x | x | x | 4 | x | x | x | 5 | x | x | x | ------------------------- I have 5 in dividual input boxes they can submit, and they are all being inputted into an array so i have $event[] , $link[] , $date[]. I cant figure out how to take the arrays and have them update the db... Any help would be greatly appreciated...Thanks! Quote Link to comment Share on other sites More sharing options...
Stooney Posted August 3, 2008 Share Posted August 3, 2008 Do you mean there will be 5 things per input box? Like 5 events, 5 links, 5 dates? Quote Link to comment Share on other sites More sharing options...
vicodin Posted August 3, 2008 Author Share Posted August 3, 2008 I have this echoing 5 times so there is 5 rows of it. echo "<tr>"; echo '<td class="event"><input type="text" name="enum[]" value="'.$row['num'].'" maxsize="1" size="5"></td>'; echo '<td class="event"><input type="text" name="event[]" value="'.$row['event'].'" size="25"></td>'; echo '<td class="event"><input type="text" name="elink[]" value="'.$row['link'].'" size="25"></td>'; echo '<td class="event"><input type="text" name="edate[]" value="'.$row['date'].'" size="10"></td>'; echo "</tr>"; echo "<tr>"; echo '<td class="event"><input type="text" name="enum[]" value="'.$row['num'].'" maxsize="1" size="5"></td>'; echo '<td class="event"><input type="text" name="event[]" value="'.$row['event'].'" size="25"></td>'; echo '<td class="event"><input type="text" name="elink[]" value="'.$row['link'].'" size="25"></td>'; echo '<td class="event"><input type="text" name="edate[]" value="'.$row['date'].'" size="10"></td>'; echo "</tr>"; echo "<tr>"; echo '<td class="event"><input type="text" name="enum[]" value="'.$row['num'].'" maxsize="1" size="5"></td>'; echo '<td class="event"><input type="text" name="event[]" value="'.$row['event'].'" size="25"></td>'; echo '<td class="event"><input type="text" name="elink[]" value="'.$row['link'].'" size="25"></td>'; echo '<td class="event"><input type="text" name="edate[]" value="'.$row['date'].'" size="10"></td>'; echo "</tr>"; echo "<tr>"; echo '<td class="event"><input type="text" name="enum[]" value="'.$row['num'].'" maxsize="1" size="5"></td>'; echo '<td class="event"><input type="text" name="event[]" value="'.$row['event'].'" size="25"></td>'; echo '<td class="event"><input type="text" name="elink[]" value="'.$row['link'].'" size="25"></td>'; echo '<td class="event"><input type="text" name="edate[]" value="'.$row['date'].'" size="10"></td>'; echo "</tr>"; echo "<tr>"; echo '<td class="event"><input type="text" name="enum[]" value="'.$row['num'].'" maxsize="1" size="5"></td>'; echo '<td class="event"><input type="text" name="event[]" value="'.$row['event'].'" size="25"></td>'; echo '<td class="event"><input type="text" name="elink[]" value="'.$row['link'].'" size="25"></td>'; echo '<td class="event"><input type="text" name="edate[]" value="'.$row['date'].'" size="10"></td>'; echo "</tr>"; That brings up another question... i dont even know if that will post as an array will it? Quote Link to comment Share on other sites More sharing options...
genericnumber1 Posted August 3, 2008 Share Posted August 3, 2008 Your description is a little ambiguous, especially since you didn't mention having the ids in an array, but I'll assume you just forgot to mention that... Try something like this... <?php for($i = 0; $i < count($id); ++$i) { // Put in your own code to clean the arrays to make sure people aren't sql injecting $query = "UPDATE table SET Event = '{$event[$i]}', Link = '{$link[$i]}', Date = '{$date[$i]}' WHERE ID = {$id[$i]}"; // Put in your own query implementation here } ?> Of course that isn't copy/paste code, but maybe something to give you a general idea of what you need to do. Quote Link to comment Share on other sites More sharing options...
vicodin Posted August 3, 2008 Author Share Posted August 3, 2008 Im pretty sure i get what your getting at... In the form i have for the name (input type ="text" name ="link[]") would i on the next page have $_POST['link[]'] or $_POST['link'][] to get it? Quote Link to comment Share on other sites More sharing options...
genericnumber1 Posted August 3, 2008 Share Posted August 3, 2008 $_POST['link'][0] would hold the first link entry $_POST['link'][1] the next, etc. Quote Link to comment Share on other sites More sharing options...
vicodin Posted August 3, 2008 Author Share Posted August 3, 2008 Thank you very much for the help! 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.