dougekui1518 2015-11-19 11:20
浏览 26
已采纳

html动态表打印到php

I need some help...

I've created a form with a dynamic table in it. I would like to learn how to pass it through php and echo/print it to a php page to save the page as pdf.

I am stuck on this part. I've looked everywhere for some answers and I cant seem to be finding anything.

<form action="display_form.php" method="POST">
<table id="dataTable" width="auto" style="margin:-4px 0 0 0;" cellspacing="0px">
    <tr>
        <td style="width:20px;"><INPUT type="checkbox" name="chk" /></td>
        <td><INPUT type="text" name="step" style="width:160px;" autocomplete="on" placeholder="step" required/></td>
        <td><INPUT type="text" name="url" style="width:62px;" autocomplete="on" placeholder="url" required/></td>
        <td><INPUT type="text" name="process" style="width:63px;" autocomplete="on" placeholder="process" required/></td>
        <td>
            <SELECT name="pass-fail" style="width:100px;">
                <OPTION value="Pass">one</OPTION>
                <OPTION value="Fail">two</OPTION>
            </SELECT>
        </td>
        <td><INPUT type="text" name="comment" style="width:190px;" autocomplete="on" placeholder="Comment" required/></td>
</table>
<INPUT type="button" value="Add row" onclick="addRow('dataTable')" />
<INPUT type="button" value="Delete row" onclick="deleteRow('dataTable')" />
<INPUT type="submit" value="Send"/>

I have called the php file display_form.php where I would like to display the dynamic table data in the. The function to save it as a pdf is in there as well. But I am mainly after the printing of the form to the php file. I am having no luck there at all!

I'm not worried on posting the table to mysql. I have other ways where i don't need it in mysql

I would really appreciate the help

  • 写回答

4条回答 默认 最新

  • dongpao1083 2015-11-19 11:27
    关注

    2 things

    • you have not closed tr

    Next

    Make all input elements as array. Then you can fetch them in your php file

     <td style="width:20px;"><INPUT type="checkbox" name="chk[]" /></td>
        <td><INPUT type="text" name="step[]" style="width:160px;" autocomplete="on" placeholder="step" required/></td>
        <td><INPUT type="text" name="url[]" style="width:62px;" autocomplete="on" placeholder="url" required/></td>
        <td><INPUT type="text" name="process[]" style="width:63px;" autocomplete="on" placeholder="process" required/></td>
        <td>
            <SELECT name="pass-fail[]" style="width:100px;">
                <OPTION value="Pass">one</OPTION>
                <OPTION value="Fail">two</OPTION>
            </SELECT>
        </td>
        <td><INPUT type="text" name="comment[]" style="width:190px;" autocomplete="on" placeholder="Comment" required/></td>
    

    In your php file, use foreach loop to get all the values.

      $i = 0;
        $array = array();
        foreach ($_POST['step'] as $row) {
            $array[$i]['step'] = $row;
            $array[$i]['chk'] = isset($_POST['ckh'][$i]) ? 1 : 0;
            $array[$i]['url'] = $_POST['url'][$i];
            $i++;
            //...//so on
        }
    
        print_R($array);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 BP神经网络控制倒立摆
  • ¥20 要这个数学建模编程的代码 并且能完整允许出来结果 完整的过程和数据的结果
  • ¥15 html5+css和javascript有人可以帮吗?图片要怎么插入代码里面啊
  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算