Jump to content

Archived

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

roland

Multiple row update

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]

Share this post


Link to post
Share on other sites

×

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.