使用post变量传递表数据

时间:2011-08-03 20:40:23

标签: php

基本上我有一个表,其中包含来自数据库的一堆数字,其中包含总计/小计的列。我不打算将任何总数添加到数据库中,但我需要将总数从一个页面传递到下一个页面。我似乎无法正确地将它们作为post变量使用PHP传递...我想知道这是否是一个糟糕的策略,其次,我应该做什么呢?

如果这是可能的,我该怎么做呢?我无法在<之间得到文本。 td>来自使用$ _POST ['tdname']。

示例代码:

<form method="POST" action="newcivilreport2.php">

            <div style="width:800px;text-align:left;margin:0 auto;padding-bottom:5px;">A. PENDING BALANCE</div>
            <table border="1" style="width:800px;" ID="tableA">
            <th style="width:40%;"></th>
            <th style="width:15%;">Civil</th>
            <th style="width:15%;">Asbestos</th>
            <th style="width:15%;">Domestic</th>
            <th style="width:15%;">Total</th>
            <tr>
            <td>1. Pending Balance from Previous Month</td>
            <td id="PendingCivil" name="PendingCivil">66</td>
            <td id="PendingAsbestos">0</td>
            <td id="PendingDomestic">0</td>
            <td id="PendingTotal">0</td>
            </tr>
            </table> 
<input type="submit" value="Save and Continue -->"></form></div>

newcivilreport2.php:

<?php
    $_POST['PendingCivil'];
?>

2 个答案:

答案 0 :(得分:6)

POST只会发送<input type='text|file|hidden|ect' />之类的输入。也许您想使用AJAX。例如:

<table id="tData">
     <tbody>
         <tr>
             <td class='dataVal1'>100</td>
      ...

$(document).ready(function() {
    var toServer = {};
    var data = $('#tData tbody tr td').each(function(key, value) {
        toServer[$(this).attr('id')] = $(this).text();
    });
    $.ajax({
        url: 'page.php',
        data: toServer,
        type: 'POST'
    })
});

答案 1 :(得分:3)

表的<td>标记不提供表单的值。

为帖子使用隐藏字段:
http://www.w3schools.com/tags/att_input_type.asp

...
<td>1. Pending Balance from Previous Month</td>
<td id="PendingCivil">66<input type="hidden" name="PendingCivil" value="66"></td>
...

此外,它是否在表格内?