wrathican Posted July 20, 2008 Share Posted July 20, 2008 hey peeps. what i have is a 'form' that shows a thumbnail with an input field underneath it. the form can have varying amounts of thumbnails. because of this what i need to do is update multiple entries in a database with the new values from the input fields. so my form would look something like this: $query = "select * from table"; $result = mysql_query($query); ?> <form> <?php while($row = mysql_fetch_array($result)){ $img = $row['table_image']; $title = $row['table_title']; $imgId = $row['table_id']; ?> <img src="<?php echo $image; ?>" alt="<?php echo $title; ?>" /><br /> <input type="hidden" name="imageid" value="<?php echo $imgId; ?>" /> <input type="text" name="title" /> <?php } ?> <input type="submit" name="send" value="Send" /> </form> so that displays a list of images with a box underneath it. what i need to do now is process the updates. how would i process it? Link to comment https://forums.phpfreaks.com/topic/115720-updating-multiple-entries-in-a-single-table/ Share on other sites More sharing options...
vicodin Posted July 20, 2008 Share Posted July 20, 2008 mysql_select_db("Your DataBase") or die(mysql_error()); mysql_query("UPDATE $YourTable SET $YourColumn = '$New-Thing-Your-Putting-In-To-The-DB' WHERE id = '$where'") or die (mysql_error()); Link to comment https://forums.phpfreaks.com/topic/115720-updating-multiple-entries-in-a-single-table/#findComment-594918 Share on other sites More sharing options...
wrathican Posted July 20, 2008 Author Share Posted July 20, 2008 hey, thanks for the reply. im sorry but i forgot to say i know how to update databases. what im looking to do i a mass update, so on my processing script it would, as i imagine it, look something like <?php $title = $_POST['title']; $imgid = $_POST['imageid']; while(!empty($title) { $query = "UPDATE table SET table_title='".."' WHERE table_id='".$imgid."'"; $result = mysql_query($query); } ?> Link to comment https://forums.phpfreaks.com/topic/115720-updating-multiple-entries-in-a-single-table/#findComment-594951 Share on other sites More sharing options...
gizmola Posted July 20, 2008 Share Posted July 20, 2008 Insert or Update? If what you're going to do is use the selections to insert rows in some table, then with insert statements you can do: INSERT INTO myTable (id, someval) VALUES (3, 5),(3, 6),(3, 9) Hopefully you get the idea. These inserts willl all occur in one transaction so it's very efficient. Link to comment https://forums.phpfreaks.com/topic/115720-updating-multiple-entries-in-a-single-table/#findComment-594954 Share on other sites More sharing options...
wrathican Posted July 20, 2008 Author Share Posted July 20, 2008 im updating. both $title and $imgid are arrays so if i printed them out they would look like this. $title: [0] = title1 [1] = title2 [2] = title3 [3] = title4 and so on, and likewise with the $imgid [0] = 1 [1] = 2 [2] = 3 [3] = 4 so i want to update each database entry using the $imgid in the where clause of my update statment. i hope im making sense Thanks for the replies. Link to comment https://forums.phpfreaks.com/topic/115720-updating-multiple-entries-in-a-single-table/#findComment-594970 Share on other sites More sharing options...
gizmola Posted May 28, 2009 Share Posted May 28, 2009 im updating. both $title and $imgid are arrays so if i printed them out they would look like this. $title: [0] = title1 [1] = title2 [2] = title3 [3] = title4 and so on, and likewise with the $imgid [0] = 1 [1] = 2 [2] = 3 [3] = 4 so i want to update each database entry using the $imgid in the where clause of my update statment. i hope im making sense Thanks for the replies. I know this is an old topic, but I never did provide the answer, which is --- you have to do individual updates statements for each. Link to comment https://forums.phpfreaks.com/topic/115720-updating-multiple-entries-in-a-single-table/#findComment-843720 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.