Jump to content

Updating mysql


vicodin

Recommended Posts

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!

Link to comment
Share on other sites

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?

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.