SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Thread: array in a form

  1. #1
    SitePoint Addict
    Join Date
    Oct 2010
    Posts
    292
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    array in a form

    please the result set i was getting from the values in a form was initially grouping two values in an array thats the [Pquantity] and [Pidno],but after adjusting the form to include another [Tprice], the array comes back splitting the valueas into individual arrays e.g and also including my button name as a key, ow can i retain the values as an array

    the first scenario

    Array ( [item] => Array ( [0] => Array ( [Pquantity] => 6 [Pidno] => 6 ) [1] => Array ( [Pquantity] => 7 [Pidno] => 4 ) [2] => Array( [Pquantity] => 8 [Pidno] => 1 ) [3] => Array( [Pquantity] => 9 [Pidno] => 2 ) ) )

    the second scenario

    Array ( [item] => Array ( [0] => Array ( [Pquantity] => 3 ) [1] => Array ( [Pidno] => 3 ) [2] => Array ( [Tprice] => 120 ) [3] => Array ( [Pquantity] => 2 ) [4] => Array ( [Pidno] => 2 ) [5] => Array ( [Tprice] => 60 ) [6] => Array ( [Pquantity] => 1 ) [7] => Array ( [Pidno] => 1 ) [8] => Array ( [Tprice] => 20 ) ) [submit1] => UPDATE )

    this is the form

    PHP Code:
    <?php
    // Get DB results and loop, outputting table rows with counter
    $pplresult mysql_query("SELECT * FROM repplac WHERE Uname = '{$_SESSION['username']}'") or die(mysql_error());
    while (
    $row mysql_fetch_assoc($pplresult)) {
    echo 
    "
    <tr>
    <td>"
    .htmlspecialchars($row['Sname'])."</td>
    <td>"
    .htmlspecialchars($row['Pname'])."</td>
    <td>"
    .htmlspecialchars($row['Psize'])."</td>
    <td>"
    .htmlspecialchars($row['Pcolour'])."</td>
    <td>
    <input type='text' name='item[
    $i][Pquantity]' id='Pquantity' value='".htmlspecialchars($row['Pquantity'])."' />
    <input type='hidden' name='item[
    $i][Pidno]' id='Pidno' value='".htmlspecialchars($row['Pidno'])."' />
    </td>
    <td>"
    .htmlspecialchars($row['Price'])."</td>
    <td>
    <input type='text' name='item[
    $i][Tprice]' id='Pquantity' value='".htmlspecialchars($row['Tprice'])."' readonly>
    </td>
    <td><a href='deleteproduct.php?del="
    .htmlspecialchars($row['Pidno'])."'>delete</a></td>
    </tr>"
    ;
    }
       
    $pplresult mysql_query("SELECT * FROM repplac WHERE Uname = '{$_SESSION['username']}'") or die(mysql_error());
      while (
    $row mysql_fetch_assoc($pplresult)) 
       
    //echo $row['Pquantity'] * $row['Price'];
      
    {
      
    $totalprice += $row['Tprice'];
      }
      
    //echo "$totalprice";


         
    ?>
         <tr>
                <th>Total Price</th>
                <th><?php echo $totalprice?></th>

            </tr>
    <!--Close table and form-->

    </table>
    <input type='submit' name='submit1' value='UPDATE' />
    <input type='submit' name='submit2' value='SUBMIT' />
    </form>

  2. #2
    SitePoint Addict
    Join Date
    Oct 2010
    Posts
    292
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    thanks i have sorted it


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •