Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-16-2007, 04:35 PM   PM User | #1
dprichard
Regular Coder

 
Join Date: Jul 2004
Location: Tampa
Posts: 221
Thanks: 22
Thanked 0 Times in 0 Posts
dprichard is an unknown quantity at this point
Updating Multiple Rows

I am trying to update multiple rows with one submit button.

I currently have a table that repeats out the following form for each folder in the database:

Code:
<form name="form1" method="post" action="<?php $_SERVER['PHP_SELF']; ?>">
                      <label>
                      <div align="center">
                        <input name="updateorder" type="hidden" id="updateorder" value="updateorder">
                        <input type="hidden" name="dcid" id="dcid" value="<?php echo $row_categories['dcid']; ?>">
                        <input type="hidden" name="dcparent" id="dcparent" value="<?php echo $row_categories['dcparent']; ?>">
                        <input name="dcorder" type="text" id="dcorder" size="3" maxlength="3" value="<?php echo $row_categories['dcorder']; ?>">
                        <input name="submit2" type="image" src="/images/refresh.png" alt="Refresh Item" align="middle" width="16" height="16">
                      </div>
                      </label>
                                                            <div align="center"></div>
                    </form>
Then I use this update statement to update the database.

PHP Code:
if(isset($_POST['updateorder'])) {
$dcorder mysql_real_escape_string($_POST['dcorder']);
$dcid mysql_real_escape_string($_POST['dcid']);
$updateorder mysql_query("UPDATE documentcategories SET dcorder='$dcorder' WHERE dcid='$dcid'") or die(mysql_error());

I would like to be able to encompass the entire table and update them with one button when submitted instead of having to update one box, then submit and the next box then submit.

Any help would be greatly appreciated!!!
__________________
David A. Prichard

Computer Support Tampa - Computer Support Chicago - Technology Blog
dprichard is offline   Reply With Quote
Old 07-16-2007, 06:16 PM   PM User | #2
NancyJ
Senior Coder

 
NancyJ's Avatar
 
Join Date: Feb 2005
Location: Bradford, UK
Posts: 3,162
Thanks: 19
Thanked 65 Times in 64 Posts
NancyJ will become famous soon enough
You can use form field arrays.

eg.
you name your fields
name = "data[<?=$row_categories['dcid']?>][nameoffield]"

then when you submit the form you'll get data like

Code:
data => array(
                 1 => array( 
                          dcparent => dcparent_value
                          dcorder => dcorder_value
                       )
                  2=> array( 
                          dcparent => dcparent_value
                          dcorder => dcorder_value
                       )
)
Then you would do something like this :

PHP Code:
if(isset($_POST['updateorder'])) {
  foreach(
$_POST['data'] as $id => $array)
  {
  
       
$dcorder mysql_real_escape_string($array['dcorder']);
       
$id mysql_real_escape_string($id);
       
$updateorder mysql_query("UPDATE documentcategories SET dcorder='$dcorder' WHERE dcid='$id'") or die(mysql_error());
  }

__________________
http://www.hazelryan.co.uk
NancyJ is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:49 PM.


Advertisement
Log in to turn off these ads.