而和数组(在一个表格中)

时间:2012-02-16 09:47:19

标签: php

请从表格中的值得到的结果集最初将数组中的两个值分组为[Pquantity]和[Pidno],但在调整表格以包含另一个[Tprice]后,阵列返回将valueas拆分为单个数组,例如并将我的按钮名称作为键,ow可以将值保留为数组

第一个场景

  

数组([item] =>数组([0] =>数组([Pquantity] => 6 [Pidno] => 6   )[1] =>数组([Pquantity] => 7 [Pidno] => 4)[2] =>阵列(   [Pquantity] => 8 [Pidno] => 1)[3] =>数组([Pquantity] => 9   [Pidno] => 2)))

第二种情况

  

Array([item] => Array([0] => Array([Pquantity] => 3)[1] =>   数组([Pidno] => 3)[2] =>数组([Tprice] => 120)[3] =>阵列(   [Pquantity] => 2)[4] =>数组([Pidno] => 2)[5] =>阵列(   [Tprice] => 60)[6] =>数组([Pquantity] => 1)[7] =>阵列(   [Pidno] => 1)[8] =>数组([Tprice] => 20))[submit1] =>更新)

这是表格

  <?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>

0 个答案:

没有答案