Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
299 views
in Technique[技术] by (71.8m points)

php - why the appended row's data didn't displayed after being submitted?

this is my php code(1st page):

        <table width="600px" id="project">
            <tr>
                <td>1</td>
                <td><textarea name="pro_1" cols="100" rows="2"></textarea></td>
            </tr>
            <tr>
                <td>2</td>
                <td><textarea name="pro_2" cols="100" rows="2"></textarea></td>
            </tr>
            <tr>
                <td>3</td>
                <td><textarea name="pro_3" cols="100" rows="2"></textarea></td>
            </tr>
            <input id="addbtn" type="button" name="addbtn" value="ADD">

incorporated with javascript for append the row when button is clicked:

$("#addbtn").click(function(){
    var num=parseInt($("#project tr:last").text());
        num+=1;
            $("#project").append("<tr><td>"+num+"</td><td><textarea name='pro_"+num+"' cols='100' rows='2'></textarea></td></tr>");
                });

The 2nd page is the important page where all data from 1st page display on it:

<table width="600px" id="project">
            <tr>
                <td>1</td>
                <td><?php echo $_POST["pro_1"]; ?></td>
            </tr>
            <tr>
                <td>2</td>
                <td><?php echo $_POST["pro_2"]; ?></td>
            </tr>
            <tr>
                <td>3</td>
                <td><?php echo $_POST["pro_3"];?></td>
            </tr>
</table>

My problem is that the data of appended row didn't show on 2nd page.How to make it? The output as below:

enter image description here

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

On the second page do something like this:

<table width="600px" id="project">
    <?php foreach($_POST as $key => $value) { ?>
    <tr>
        <td><?php echo $key; ?></td>
        <td><?php echo $value; ?></td>
    </tr>
    <?php } ?>
</table>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...