Jump to content

Multiple row update


roland

Recommended Posts

Anybody could help me! I retrieved data from my database table and print them inside the form then I want them to edit. Could anybody give a script on how to update a multiple rows...

I have 500 rows with 5 fields in my database table I retrieved them all and output them inside the form so that I can edit them immediately. On the left in each row i put checked box so that i can check which row i want to edit. Let say I checked 5 rows from row 200:

row 200 i changed field 4 and 5
row 201 i changed field 1 and 2
etc.

How can i process these??? please help me!!!

Here is waht I did:

UPDATE book SET title="", author="", edition="", callnumber="" WHERE id="";

I know it will not work.

Here is my output data inside the form:

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]
print "<form method=\"post\" action=\"insertResult2.php\">";
print "<table width=\"934\" border=\"0\" cellspacing=\"8\" class=\"texxt\" align=\"center\">";
print "<tr>";
print "<td bgcolor=\"#FFFFFF\"><strong>ID</strong></td>";
print "<td bgcolor=\"#FFFFFF\"><strong>&nbsp;</strong></td>";
print "<td bgcolor=\"#FFFFFF\"><strong>Authors</strong></td>";
print "<td bgcolor=\"#FFFFFF\"><strong>Titles</strong></td>";
print "<td bgcolor=\"#FFFFFF\"><strong>Editors</strong></td>";
print "<td bgcolor=\"#FFFFFF\"><strong>Call No.</strong></td>";
print "<td bgcolor=\"#FFFFFF\"><strong>Edition</strong></td>";
print "<td bgcolor=\"#FFFFFF\"><strong>Year</strong></td>";
print "<td bgcolor=\"#FFFFFF\"><strong>Notes</strong></td>";
print "</tr>";

$color_a = "#CCCCCC";
$color_b = "#8B8B8B";
include "../../HTML/Inc/connect.inc";
$query = "SELECT id, author1, title, callnumber, editions, year, notes FROM book WHERE author1 = 'Webster'";
$result = mysql_query($query,$link) or die("Cannot read record: ".mysql_error());
while($i++ <= mysql_num_rows($result) && $rs = mysql_fetch_array($result))
{
$id[$i]=$rs['id'];
$authors[$i]=$rs['author1'];
$title[$i]=$rs['title'];
$callnumber[$i]=$rs['callnumber'];
$editions[$i]=$rs['editions'];
$year[$i]=$rs['year'];
$notes[$i]=$rs['notes'];
$mod = ($i % 2);

print "<tr>";
print "<td bgcolor=\"";
if($mod == 0){echo $color_a;}else {echo $color_b;}
print "\">$i</td>";
print "<td bgcolor=\"";
if($mod == 0){echo $color_a;}else {echo $color_b;}
print "\"><input type=\"checkbox\" name=\"box$i\" value=\"$id[$i]\"></td>";
print "<td bgcolor=\"";
if($mod == 0){echo $color_a;}else {echo $color_b;}
print "\"><textarea name=\"authors$i\" cols=\"8\">$authors[$i]</textarea></td>";
print "<td bgcolor=\"";
if($mod == 0){echo $color_a;}else {echo $color_b;}
print "\"><textarea name=\"title$i\">$title[$i]</textarea></td>";
print "<td bgcolor=\"";
if($mod == 0){echo $color_a;}else {echo $color_b;}
print "\"><input size=\"5\" type=\"text\" name=\"editors$i\" value=\"$editors[$i]\"></td>";
print "<td bgcolor=\"";
if($mod == 0){echo $color_a;}else {echo $color_b;}
print "\"><input type=\"text\" name=\"callnumber$i\" value=\"$callnumber[$i]\"></td>";
print "<td bgcolor=\"";
if($mod == 0){echo $color_a;}else {echo $color_b;}
print "\"><input size=\"5\" type=\"text\" name=\"editions$i\" value=\"$editions[$i]\"></td>";
print "<td bgcolor=\"";
if($mod == 0){echo $color_a;}else {echo $color_b;}
print "\"><input size=\"2\" type=\"text\" name=\"year$i\" value=\"$year[$i]\"></td>";
print "<td bgcolor=\"";
if($mod == 0){echo $color_a;}else {echo $color_b;}
print "\"><input type=\"text\" name=\"notes$i\" value=\"$notes[$i]\"></td>";
print "</tr>";
}//End While
print "<tr>";
print "<td bgcolor=\""; if($mod == 0){echo $color_a;}else {echo $color_b;}
print "\">&nbsp;</td>";
print "<td bgcolor=\""; if($mod == 0){echo $color_a;}else {echo $color_b;}
print "\">&nbsp;</td>";
print "<td bgcolor=\""; if($mod == 0){echo $color_a;}else {echo $color_b;}
print "\">&nbsp;</td>";
print "<td bgcolor=\""; if($mod == 0){echo $color_a;}else {echo $color_b;}
print "\">&nbsp;</td>";
print "<td bgcolor=\""; if($mod == 0){echo $color_a;}else {echo $color_b;}
print "\">&nbsp;</td>";
print "<td bgcolor=\""; if($mod == 0){echo $color_a;}else {echo $color_b;}
print "\">&nbsp;</td>";
print "<td bgcolor=\""; if($mod == 0){echo $color_a;}else {echo $color_b;}
print "\">&nbsp;</td>";
print "<td bgcolor=\""; if($mod == 0){echo $color_a;}else {echo $color_b;}
print "\">&nbsp;</td>";
print "<td bgcolor=\""; if($mod == 0){echo $color_a;}else {echo $color_b;}
print "\"><input type=\"Submit\" value=\"Update!\"></td>";
print "<input type=\"hidden\" name=\"edit_book\" value=\"book_record\">";
print "</tr>";

print "</table>";
print "</form>";
[/quote]
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.