将php结果保存在不同的表中

时间:2013-09-20 02:29:51

标签: php

我有一个页面可以使用fetch数组显示结果。因为我在页面中添加了一个字段NINS-LEC列,所以我很难从另一个数据库表中保存它。我该如何解决这个问题?

<html>
<head>   
</head>
<body>
<?php
$server = mysql_connect("localhost","root", "");
$db =  mysql_select_db("bsswebtool",$server);
$query = mysql_query("select * from soa where InvoiceAccNum  in 
('7000068191',
'7000068205',
'7000068060',
'7000068094',
'7000068078',
'7000068086',
'7000068311',
'7000068019',
'7000068299')");
$num_rows = mysql_num_rows($query);
    ?>
    <table class="striped">
        <tr class="header">
            <td>Groupings</td>
            <td>InvoiceAccNum</td>
            <td>AccountFirstName</td>
            <td>SubsidiaryCode</td>
            <td>HandlingCode</td>

        </tr>
        <?php
           while ($row = mysql_fetch_array($query)) {
               echo "<tr>";
               echo "<td>".'NINS_LEC'."</td>"; //change group name
               echo "<td>".$row['InvoiceAccNum']."</td>";
               echo "<td>".$row['AccountFirstName']."</td>";
               echo "<td>".$row['SubsidiaryCode']."</td>";
               echo "<td>".$row['HandlingCode']."</td>";
               echo "</tr>";
           }
        ?>
    </table>
       <?echo "$num_rows Rows\n";?>
 <? echo 
"<fieldset>
<table width='680'><tr>
<td colspan='4' align='center'>
<input type='submit' name='btn_save' value='Save'>
</td></tr></table></fieldset></form>";
}?>

</body>

这是我将其保存到新表的代码  $ query_insert_outbound =“INSERT INTO NINS_LEC(rid,invoiceno,grouping,Address,Subscribercode,AccountTitle,AccountFirstName,InvoiceAccNum,InvoiceNumber,HandlingCode,SubsidiaryCode,LastBillBal,CurrentCharges,TotalDueAmt,Rental_othrC,VatTag,UsageTag,OctTag,BalanceCarryFwd,PaymentReceived,Adjustments,目前,Over30days,Over60days,Over90days,Over120Days,CREDITLIMIT,WithoutTaxTag,InvoiceCurrency,EXCHANGERATE,AsOnDate)             VALUES( '', '$ invoiceno',                  '$分组',                  '$ Address',                   '$ Subscribercode',                   '$ AccountTitle',                   '$ AccountFirstName',                   '$ InvoiceAccNum',                   '$ InvoiceNumber',                   '$ HandlingCode',                   '$ SubsidiaryCode',                  '$ LastBillBal',                  '$ CurrentCharges',                  '$ TotalDueAmt',                  '$ Rental_othrC',                     '$ VatTag',                     '$ UsageTag',                  '$ OctTag',                  '$ BalanceCarryFwd',                  '$ PaymentReceived',                  '$调整',                  '$当前',                  '$ Over30days',                  '$ Over60days',                  '$ Over90days',                  '$ Over120Days',                  '$ CREDITLIMIT',                  '$ WithoutTaxTag',                  '$ InvoiceCurrency',                  '$ EXCHANGERATE',                  '$ AsOnDate')“;

    mysql_select_db("bsswebtool",$server);  
    $server = mysql_connect("localhost","root", "");            
    $insert_query_query =mysql_query($query_insert_outbound) or die(mysql_error());
   $insert_rows_affected= mysql_num_rows($insert_query_query);
//echo $query_insert_outbound;?>

这只是我从表查询中获取数据的示例代码。我需要将结果保存到其他表格谢谢。

1 个答案:

答案 0 :(得分:0)

我希望,您已经可以保存,您需要在表单中声明字段。表单帖子可能会显示表单字段,在您的情况下,由于您只是在表格中显示数据,因此不会发生。也许你可以采取以下方法(注意我已经改变了TD元素以形成元素:

<html>
<head>   
</head>
<body>
<?php
$server = mysql_connect("localhost","root", "");
$db =  mysql_select_db("bsswebtool",$server);
$query = mysql_query("select * from soa where InvoiceAccNum  in 
('7000068191',
'7000068205',
'7000068060',
'7000068094',
'7000068078',
'7000068086',
'7000068311',
'7000068019',
'7000068299')");
$num_rows = mysql_num_rows($query);
    ?>
    <form name="vw_ob_save" method="post">
    <table class="striped">
        <tr class="header">
            <td>Groupings</td>
            <td>InvoiceAccNum</td>
            <td>AccountFirstName</td>
            <td>SubsidiaryCode</td>
            <td>HandlingCode</td>

        </tr>
        <?php
           while ($row = mysql_fetch_array($query)) {
               echo "<tr>";
               echo "<td>".'NINS_LEC'."</td>"; //change group name
               echo "<td><input type=\"text\" name=\"invoice_num\" value=\"". stripslashes($row['InvoiceAccNum']) ."\" /></td>";
               echo "<td><input type=\"text\" name=\"first_name\" value=\"". stripslashes($row['AccountFirstName']) . "\" /></td>";
               echo "<td><input type=\"text\" name=\"subs_code\" value=\"". stripslashes($row['SubsidiaryCode']) ."\" /></td>";
               echo "<td><input type=\"text\" name=\"handling_code\" value=\"" . stripslashes($row['HandlingCode']) . "\" /></td>";
               echo "</tr>";
           }
        ?>
    </table>
       <?echo "$num_rows Rows\n";?>
 <? echo 
<table width='680'><tr>
<td colspan='4' align='center'>
<input type='submit' name='btn_save' value='Save'>
</td></tr></table>
</form>";
}?>

</body>

如果您需要进一步的帮助,请与我们联系。