Re: Update multiple records from a text field

From: Date: Fri, 02 Apr 2004 18:40:38 +0000
Subject: Re: Update multiple records from a text field
References: 1 2 3  Groups: php.windows 
Request: Send a blank email to php-windows+get-23355@lists.php.net to get a copy of this message
Kaizer Boab wrote:
Hi Justin, I only have the one qty field in the View Cart page. It is part of a loop to pull out all the quantities from the cart. It is retrieved via the script below: <?php
    // Query the cart table and select all the items from the table.
    $resultCart = mysql_query("SELECT * FROM cart, products WHERE
cart.albumId = products.albumId AND cart.trackerId = $trackerId ORDER by products.albumTitle ASC");
    while($row_rsCart = mysql_fetch_array($resultCart))
    {
     $cost = $row_rsCart['albumPrice'] * $row_rsCart['qty'];
     $cost = number_format ($cost, 2);
     $subTotal = number_format ($subTotal, 2);
     $subTotal += $cost;
?>
            <tr>
              <td align="left"><?php echo $row_rsCart['albumArtist'];?></td>
              <td align="left"><?php echo $row_rsCart['albumTitle'];?></td>
              <td align="right"><?php echo $cost;?></td>
             <td align="right
                <input name="qty" type="text" size="2" value="<?php echo
$row_rsCart['qty'];?>" />
             </td>
            </tr>
            <?php  }// END while loop;?>
Since the qty text field is only one box in a loop, naming it won't help. Is there another way I could achieve the update? Thanx for your help.
Looks like you're naming all of your quantity text boxes "qty". You need to use different var names to make multuple values come back. For instance you could use "qty[]" to have the results come back in an array. Or you could use qty[x] where x is a specific # so that you know which product to update. -- paperCrane <Justin Patrin>
You need to use what I said in my reply. Change name="qty" to name="qty[]" or name="qty[some database id]". -- paperCrane <Justin Patrin>

« previous php.windows (#23355) next »