Re: Multiple Update from one form

From: Date: Wed, 19 May 2004 00:13:16 +0000
Subject: Re: Multiple Update from one form
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-186508@lists.php.net to get a copy of this message
Enda Yes, you need the multi-dimensional array as you want to keep the data for the same line together. Miles At 09:03 PM 5/18/2004, Enda Nagle - Lists wrote:
Hi Miles, Thanks for the reply. I see what you're doing there and had looked at the foreach() functionality, but am I right in saying that I still need to use the multidimensional array since there are three variables in each line? (id, tracking, kb_ship)? Enda -- On 19/05/2004 00:58, "Miles Thompson" <milesthompson@ns.sympatico.ca> wrote: At 07:56 PM 5/18/2004, Enda Nagle - Lists wrote: Its OK guys, Got something else myself. Here's the solution... Any suggestions appreciated... ///////////////////////////// // UPDATE PART ///////////////////////////// $i=1; //while ($ordersinfo[$i]) while ($i < $total) { $session = $ordersinfo[$i][session]; $tracking = $ordersinfo[$i][tracking]; $kb_ship = $ordersinfo[$i][kb_ship]; $update = mysql_query("UPDATE products_orders SET tracking='$tracking', kb_ship='$kb_ship' WHERE session='$session'") or die (mysql_error()); $i++; } ///////////////////////////// // MAIN PART ///////////////////////////// ... <td align=\"default\" width=\"100\"><input type=text name=\"ordersinfo[$i][tracking]\" value=\"" . $roworders[tracking] . "\" size=25></td> ... Regards Enda -- On 18/05/2004 23:20, "Enda Nagle - Lists" <lists@nightsol.net> wrote:
Hi I have a current application where I am listing a table of order details, where a fulfillment company can enter the tracking number and the cost of the shipment. At present, I have up to 40 orders displayed, and when they click on the 'update' button, the code executes as
    if ((isset($tracking1)) && (isset($kb_ship1))){
      $update=mysql_query("UPDATE orders SET
tracking='$tracking1',kb_ship='$kb_ship1' WHERE order_ref =
'$ref1'",$link);
    }
And this continues as tracking 2... tracking40. I would like to implement something like foreach ($_POST["ref"]){
      $update=mysql_query("UPDATE orders SET
tracking='$tracking',kb_ship='$kb_ship' WHERE order_ref = '$ref'",$link); } Instead, but I'm not so sure how I can do this, given that form variables cannot be named the same etc. I'm sure that there's a better way that the way in which I'm doing it
at the
moment, so any input would be appreciated. Thanks Enda --
Enda, This is close to your situation, but I only needed a one dimensional array for a bulk delete. So the form part has this line:
         print( '<input type="checkbox" name=chkdelete[] value="' .
$myrow['sub_key'] . '">'); There's no need for a subscript in the form - there are presently a potential of 963 elements in this array. When we check for bulk delete it's never contiguous, we skip down the list, so array is v. sparse. And the processing part uses this loop:
         foreach ($chkdelete as $value){
                 $sql = "delete from subscriber where sub_key = '$value'";
                 $result = mysql_query($sql);
         }
This way I'm in no danger of hitting a missing subscript as I might if I used $chkdelete[ $i ], incrementing $i HTH - Miles


« previous php.general (#186508) next »