Jump to content

updating multiple entries in a single table


wrathican

Recommended Posts

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?

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);
}

?>

 

 

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.

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.

  • 10 months later...

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. 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.